Can I tell the script to wait 3 seconds before running certain code?

Can I tell the script to wait 3 seconds before running certain code? I want the gun to reload not to fast because right now it is not even 0.001 seconds.

Yes, you can use the setTimeout function for that.

setTimeout(function() {
    // your reload code here
}.bind(this), 3000);
1 Like

Another solution is to use the pc Tween library to fake a delay in executing some code:

This has the advantage of sync its execution with the app update. Window timeout will still run even if the window isn’t focused, potentially can create issues in gameplay.

1 Like

can i put the shooting code in here, i don’t want people shooting and reloading at a time.

You need a boolean that you set on true when the player pressed the R key and you have to set it on false again inside in your setTimeout function. Then make shooting only possible when the boolean is on false.

what is a boolean?

Something like below.

this.isReloading = false;

so will i do something like this
this.isReloading = true;
setTimeout(function() {
// your reload code here
}.bind(this), 3000);
this.isReloading = false;
//Shooting mechanisms

Something similar

Yes, and then if the player want to shoot you check if this.isReloading is false.