Stop request spam at the server with per-player limits, and learn why a client debounce can never protect your game.
The client can now ask via RemoteEvents — and that means it can also keep asking forever. A server that answers every request without a second thought hands out unlimited coins, or melts under a flood of fake clicks. Rate limiting is the bouncer that decides how often anyone gets in.
Remember the secure coin flow from the RemoteEvents lesson? The server rewards every CoinClicked request it receives. Here is that handler with one obvious problem:
-- ServerScriptService (this handler runs on the server)
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coinEvent = ReplicatedStorage.CoinClicked
coinEvent.OnServerEvent:Connect(function(player)
-- trust: every single click is rewarded
local stats = player:WaitForChild("leaderstats")
stats.Coins.Value += 10
end)
A human playing normally clicks maybe ten times a second — slowly enough for the tool to work. Now imagine a 's client running a :
-- on the exploiter's machine
while true do
coinEvent:FireServer()
end
Every frame, the server receives a fresh request and quietly adds 10 coins. In ten seconds an exploiter has mined more than a legitimate earns in days — and your server did all the work for it. An unrelenting client is a fact of Roblox, not a surprise attack.
An exploiter fires CoinClicked 500 times in one second. What does the unguarded server do?
You may already know the classic for buttons — a local flag that stops the same click from registering twice while a swing or a sound is playing:
-- LocalScript (on the player's computer)
local isBusy = false
button.MouseButton1Click:Connect(function()
if isBusy then return end
isBusy = true
coinEvent:FireServer()
task.wait(0.5)
isBusy = false
end)
A feels great to play with: double-clicking doesn't launch the same attack two animations at once. But look at where that code runs — on the 's computer, inside local memory. It only stops that 's own hand from clicking twice. It never runs for the server.
An exploiter doesn't click the button. They call coinEvent:FireServer() directly from their own , entirely outside your LocalScript. isBusy might as well be a different person's phone — the flood arrives at the server identically.
Keep the client for feel (no double swings, no overlap), but never rely on it for protection. Protection has to run where the real data lives: on the server.
Where does a debounce actually stop unwanted requests?
The first line of defense is a cooldown: at most one accepted request per per window. Track the last accepted time for each in a , check it before rewarding, and update it when you do reward.
-- ServerScriptService
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local coinEvent = ReplicatedStorage.CoinClicked
local COIN_COOLDOWN = 0.2 -- seconds between accepted clicks
local lastClick = {} -- UserId -> os.clock() timestamp
coinEvent.OnServerEvent:Connect(function(player)
local userId = player.UserId
local now = os.clock()
-- too soon since the last accepted click? reject silently
if now - (lastClick[userId] or 0) < COIN_COOLDOWN then
return
end
lastClick[userId] = now
local stats = player:WaitForChild("leaderstats")
stats.Coins.Value += 10
end)
Three details do the heavy lifting:
lastClick is keyed by UserId, so one fast can't drain everyone else's allowance.or 0 for the first click. A brand-new has no entry in the ; nil minus a number errors. (lastClick[userId] or 0) means "treat the past as far enough ago."A player's click should only be accepted once the cooldown window has passed. Fill in the missing line that records this accepted click so the next one has something to compare against.
if now - (lastClick[userId] or 0) < COIN_COOLDOWN then
return
end
-- record this accepted click
That lastClick grows by one entry per who ever plays, and it never shrinks — a slow memory leak. come and go, so clear each 's entry when they leave:
Players.PlayerRemoving:Connect(function(player)
lastClick[player.UserId] = nil
end)
Without this, every raid that brings a hundred new leaves a hundred entries behind forever. With it, the only ever holds the who are in the game right now.
Per- state in a server must be cleaned up in PlayerRemoving. that track per- times, counts, or flags — and never clear their keys — are a classic slow leak that shows up only after hours of uptime.
These three get mixed up constantly, and the difference matters for what you build:
0.2s between clicks).A cooldown fits actions that should be slow — one coin per click, one jump, one swing. A rate limit fits logs and quick-but-capable actions: a chat box, a stats ticker, a who can fire 10 projectiles a second but not 10,000. Roblox even has built-in protection on some APIs (like RemoteEvent:FireServer rate limits and chat throttling) — but your own rules are your responsibility.
Your sword lets a player swing at most 3 times per second. Inside a window, the 4th swing is ignored. This is a…
Put the pieces together and the economy survives a flood:
-- client reports a click (normal gameplay, debounce for feel only)
coinEvent:FireServer()
-- server decides: cooldown gates every reward
coinEvent.OnServerEvent:Connect(function(player)
local now = os.clock()
if now - (lastClick[player.UserId] or 0) < COIN_COOLDOWN then
return -- too fast: silently ignored
end
lastClick[player.UserId] = now
player.leaderstats.Coins.Value += 10
end)
os.clock() measured in a LocalScript tells you about the 's machine, not your server. Measure where you decide.Rate limiting is one gate on the road to a bulletproof economy. Next in this security path: Server Authority — keeping your rules in one trusted place — and Input Validation — double-checking everything a types or sends before you act on it.
Next up: Server Authority — keeping every rule in one trusted place, from the coin click to the shop counter.