Whats the best way to keep exploiters from spam firing remotes on the server?
Well its more of the question if you actually need a debounce or not. Code your server side code so that even if they do spam, it won’t hurt your game. (And make sure you don’t have any unprotected remote events)
Although, if you really want a debounce, you’d add it on the server side. As normal create your variable outside the OnServerEvent function, and set it to true when the event is run, wait a certain time, and then set it back to false
(Of course add the if statement for it to work as well)
But wouldn’t setting a debounce on a server script cause all clients to have to wait the debounce time?
Helpful thread:
The answer to this is to keep track of the “debounce” state for each player separately.
I do it like this:
local PlayerTimes = {}
local DebounceTime = 2 -- Change in seconds
RemoteEvent.OnServerEvent:Connect(function(Player)
if not PlayerTimes[Player] then PlayerTimes[Player] = 0 end -- Handle first time
if tick()-PlayerTimes[Player] >= DebounceTime then
PlayerTimes[Player] = tick()
-- Handle code here
end
end)
RemoteEvents could be received by the server at the same time due to lag. If this remote is for a gun that fires fast, then this would be a huge source of bugs. Follow the leaky bucket method that was described in the thread I linked.