Check gun fire-rate on single server script system?

I’m using a gun system that uses a local script per gun, and one server script, how can I handle the fire-rate checking on the server for each gun with only one server script?

My system currently just handles all the raycasting on the client, then the server just does checks and validates the hit

2 Likes

You can use a table to store the last time the player has fired a round. You really only need to store debounces for the player, not for each gun because they are so short that they wouldn’t even be able to switch guns and start firing before the old cooldown goes away.

local GunDebounce = {}

FireRemote.OnServerEvent:Connect(function(Player) 
     if GunDebounce[Player.UserId] then
          return -- If its currently on cooldown, the script doesn't continue
     end

     GunDebounce[Player.UserId] = true

     task.delay(0.05, function() -- Change 0.05 the cooldown time you want, make sure the cooldown is the same on the client and the server
          GunDebounce[Player.UserId] = nil
     end)

     -- The rest of the gun code here
end)

Hope this helps.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.