Protecting Remote Events

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?

Any help is much appreciated! :+1: :grinning:

1 Like

This conversation was had three days ago, always aim to search for older discussions prior to creating a thread.

As I said “I already made a server side cool down, which didn’t work due to lag”.

1 Like

You did something like this? -

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)

I did a very simple cool down, for example:

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.

1 Like

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.

Roblox throttles remote events so they don’t crash the network, that has nothing to do with making a weapon debounce.

You can make a debounce easily by putting an Instance in the player like @R0mAAn1CH suggested or making a debounce table.

2 Likes

If you’re actually using variables (making 'em global is even worse) for a cooldown, then it’s going to affect all players.

player1 fires event → executes code as coolDown isn’t true → coolDown = true → waits 5 seconds
player2 fires event → coolDown is true, doesn’t execute code

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 → …

2 Likes

I don’t mean to be offensive, but then why did you suggest this as an answer to a cool-down in the first place?

Thank you for understanding my problem! :+1: :grinning:
Sorry if I wasn’t clear enough.

This was the problem I was having, the cool down is affecting all players, but I didn’t know why.

So your saying i should put the word “local” in front of my variables?

because you said

So I added to the reply, that you can’t stop remote events from being spammed.

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)
3 Likes

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).

1 Like

Thanks @zamd157 and @elonrocket for the help, I really appreciate it, I’ll test it out. :+1: :grinning:

1 Like

Do I have to use table.insert? or is setting the value of CoolDown[player] to true, adding them to the table?

yes you doing

CoolDown[player] = true

will add CoolDown[player] to the table if it’s not already in there


table.insert is used for arrays, but in this case you want to use dictionaries so you can easily index CoolDown[player]

I tested it, and the cool down doesnt affect all players, It only affects the player who fired the remote event. So it works.

Thanks, I appreciate all the help :+1: :smiley:
I marked your post as solution.

1 Like