The easiest way to approach this would be creating a variable that checks if the weapon has fired and only fire if it hasn’t. You could do something like:
This isn’t a super clean way of doing it, but it should get you going in the right direction. Notice how the app marks this.sniperHasFired as false once the mouse is released.
To include a single fire on this script, you can add a timer that prevents the player from shooting too rapidly. Here is an example of how you could modify the script:
This modification introduces two new variables: canShoot and shootDelay. canShoot is a boolean that tracks whether the player is allowed to shoot again. shootDelay is the amount of time (in seconds) that must pass before the player can shoot again. The setTimeout function is used to reset canShoot after the appropriate delay.
With this modification, the player can shoot once every shootDelay seconds. You can adjust the shootDelay value to control the rate of fire.