Should I add a debounce to each remote event function individually?

This is to prevent exploiters from firing the remote too many times to cause lag. Is this a workable solution, or can it lead to problems for players?

local event = game.ReplicatedStorage.Event
local working = false
event.OnServerEvent:Connect(function()
if working then return end
working = true
-- do stuff
task.wait()
working = false
end)
1 Like

I dont recommend you do this. This could cancel actual requests to those remote events. The best way is just sanity checks

2 Likes

Server-sided floodchecks would end up acting for everyone, thus an exploiter could flood a RemoteEvent preventing any other client from legitimately using it, you could use a player debounce table to circumvent this.

RemoteEvent:FireServer() --Client fires server.

local PlayerDebounces = {}

RemoteEvent.OnServerEvent:Connect(function(Player)
	if PlayerDebounces[Player] then return end
	PlayerDebounces[Player] = true
	print(Player.Name)
	task.wait(5) --Debounce length
	PlayerDebounces[Player] = nil
end)

This can then be converted into a method for catching potential exploiters, be wary of false positives however.

RemoteEvent:FireServer() --Client fires server.

local PlayerDebounces = {}

RemoteEvent.OnServerEvent:Connect(function(Player)
	if PlayerDebounces[Player] then
		if tick() - PlayerDebounces[Player] <= 0.5 then --Client firing the RemoteEvent too frequently?
			Player:Kick() --Kick the player.
		end
	end
	PlayerDebounces[Player] = tick()
	print(Player.Name)
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.