Preventing gun firerate hacks?

Basically I have a gun system, where when the player fires it sends a fire event that just makes sure that other players can see the bullets and it also sends a hit event when the shot hits anything on the client.

The problem is, that an exploiter can easily change the firerate on the client to wipe anyone in seconds. I tried fixing it by making the fire remote cooldown, but how would I implement it into the hit event? As it can be fired any time based on where the hit position is, what time the player shot at. It’s not a raycast gun, it’s a projectile type gun.

Use a debounce (cooldown) on the client, and on the server.

Though as they said, they want to prevent “hacks” into their script. So trying to use debounce on the client is useless.

1 Like

Agree, and why use cooldown on client if this can de-sync with lag moments?

This would make it so that a gun can only be fired every 2 seconds globally, not per player.

You’d likely want a system like this:

local FireCooldowns = {}

game:GetService("ReplicatedStorage").Fire.OnServerEvent:Connect(plr,direction)
    if FireCooldowns[plr] and ((FireCooldowns[plr] + 1) > tick()) then
        return
    else
        FireCooldowns[plr] = tick()
        -- Firing logic
    end
end)

Keep in mind that while this automatically adds players, it doesn’t automatically remove them from the table when they leave.

A client side check is likely still a good idea to prevent the issue where guns feel slow and unresponsive, just make a server-sided check a bit more lenient to account for lag (±0.5 seconds or so)

It’s absolutely essential to do it on the client. The client needs immediate feedback to avoid input delay. If you only check for cooldown on the server, the client will either provide gun firing feedback for every click, or it will suffer a feedback delay based on ping. Neither of those are ideal.

Ah, my bad. You right.

This is just for chars limit

I don’t really think it make sense to add a debounce. Firstly you need different debounce for different Weapons (Rocket launcher need a Longer Cooldown than a Minigun- yeah). I would do something like this (Server):

local lastShoot = nil
function YourShootFunction()
-- Check which weapon the player is Holding and get the cooldown from the SERVER (You dont need to add a extra cooldown, you also can use the Firerate/60)
local cooldown = serverStorage.WeaponThePlayerIsUsing.Configuration.Cooldown.Value --(Very simplified)
      if lastShoot - os.Time() >= cooldown then
          Shoot()
          -- Save the Exactly time where the player Shot
          lastShoot = os.Time()
      else
          print("This Player is may a Exploiter/Shoot faster than the Firerate")
      end
end

I am currently not at home, so don’t blame me if this Syntax isn’t correct. There are Million Different ways @Inconcludable is also had a good way (maybe more Professional)

Hi, so then what is a proper or best solution?

Thanks