Hi, I have been working on a super powers game for some time now, and my game is completely dependent on Remote-Events, each power has its own cool down time in the local script I use to fire the Remote Event, but my problem is, exploiters can fire them like at 100 times per second which can ruin my game.
I have already tried making a cool down on the server side but that just makes shooting each power really laggy, which has a big effect on player experience.
How would I go about making sure my Remote Events cant be spammed by exploiters?
RemoteEvent.OnServerEvent:Connect(function(plr, etc) --Event fired
if plr:FindFirstChild("CD") == nil then --Checking if player has cooldown
local cd = Instance.new("BoolValue") --Add cooldown
cd.Parent = plr --Putting it into player so script will find it and prevent spamming
cd.Name = "CD" --Naming
game.Debris:AddItem(cd, 5) --Removing in 5 seconds
--Do other things attacks etc. here--
else
--Cooldown. Text message or anything or even just remove this.
end
end)
CoolDown = true
CoolDownTime = 5
Remote.OnServerEvent:Connect(function(player)
if CoolDown then
CooDown = false
--does power attack
wait(CoolDownTime)
CoolDown = true
end
end)
My point is, is that its server side, and for some reason because of this, it causes lag, delaying the cool down time to much longer. (sometimes its on time though).
There’s no lag when I put the cool down in my local script, but then I have the problem of exploiters…
Very nice explanation to what “exploiting is”, but unfortunately it doesnt answer my question… Because there’s no explanation to how to stop Remote Events being spammed…
Did you even read through the topic you posted to see if it answered my question?
You can’t “stop remote events from being spammed” (roblox automatically throttles them) you can only handle them properly on the server in which I just linked a post that explains how to do that well.
I know how to handle Remote Events well server side, In my case, as I explained I’m dealing with “super powers”, Its not a shop or something where I can check if the player has enough coins, The local script simply fires the server, firing the power, I’m asking: What kind of Cool down would work in my situation
The post explains how to check if the player meets the pre-set requirements to (for example) give cash/money to the player, In my case that doesnt help.
I don’t believe that to be true.
That still doesnt help me as certain powers have 20 or even 30 second cool-downs.
I don’t want exploiters firing those powers every 5 seconds with Roblox throttling them.
That’s why you need to have a cooldown per-player, by having a cache table for each of them.
local Players = game:GetService("Players")
local remote: RemoteEvent = remote_location
local playerCooldowns: { [number] : boolean} = {}
local COOLD0WN_TIME = 10
Players.PlayerAdded:Connect(function(player: Player)
playerCooldowns[player.UserId] = false
-- Code
end)
Players.PlayerRemoving:Connect(function(player: Player)
-- Cleanup
playerCooldowns[player.UserId] = nil
-- Code
end)
remote.OnServerEvent:Connect(function(player: Player)
-- Return if cooldown for player is not up
if (playerCooldowns[player.UserId]) then return end
playerCooldowns[player.UserId] = true
-- Code
wait(COOLD0WN_TIME)
playerCooldowns[player.UserId] = false
end)
player1 fires event → executes code as player coolDown isn’t true → player coolDown = true → waits 5 seconds
player2 fires event → player coolDown is false, executes code → …
no local just means the variable can’t be accessed outside of that environment, you would need to do
local CoolDown = {}
local CoolDownTime = 5
remote.OnServerEvent:Connect(function(player)
if not CoolDown[player] then
CoolDown[player] = true
wait(CoolDownTime)
CoolDown[player] = false
end
end)
That’s not the actual problem. I was just saying to use local variables because they’re indexed by offset in memory, whilst global ones are indexed in the global table (thus, local variables are faster).