Best way to detect how much time has elapsed since last shot fired to reset gun recoil?

I’ve managed to replicate gun recoil to the client, the server and the other clients, but I’m stuck on how to best reset gun recoil.

I thought of firing to the server when the mouse button is lifted up, but it will make it so that semi automatic weapons reset recoil everytime they fire.

The recoil works by:
1: both client and server start off with first shot accuracy
2: when client fires to the server and the server shoots its own bullet, recoil is recalculated and is fired to the client
3: each time recoil is recalculated, the possible spread is increased

So all that’s left is to reset the recoil after 1 second of no further fire.

The best way is probably to use tick(), store that in a variable each time the player fires their gun, then compare that with a new tick() call, and see if the time elapsed is >= X to reset the recoil.

Example:

local timer = tick()
wait(5)
print(tick() - timer) --//Difference between the stored tick() value and the current value of tick(), should be around 5 or so.
1 Like