What I meant by spam click is, let’s say a gun that has a cool down of 3 seconds after its being activated. Let’s say the cooldown script is in the local script and an exploiter has added a while true loop inside that script, which will spam FireServer() a remote event. How can I make it so that a server script can detect this because of constant spam firing the remote event? I heard that tick() can solve this, by subtracting the current tick() to the tick() that the function was called from the last call of remote event, but I can’t figure it out how. I’m pretty sure this is a very easy fix and solution.
Apparently you can use a debounce table for this. Recently read a post, and here it is: How do i make a sanity check for Remote Events / Functions - #5 by goldenstein64
Oh wow! This is very useful! Thanks! It blocks the exploiter from spam firing the event, even though it still fired, the delay function spawns a thread which the function will be enabled after 5 second which will make the debounce back to false. It’s very useful. But can you give me the way in tick() instead? I remember there’s a post with it, I want it so that it detects the seconds between the previous detection and the latest detection so I can detect that the player is trying to exploit and kick them instead.
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("doClick")
local PlayersLastTick = {}
local MinS = 1 --in seconds the minimum time between the first click and the second, decimals allowed
function doClickThing(plr)
print("Correct")
print(tick())
--insert code to execute when click is correct
end
Remote.OnServerEvent:Connect(function(plr)
if PlayersLastTick[plr.Name] then
if tick()-PlayersLastTick[plr.Name] >= MinS then
doClickThing(plr)
PlayersLastTick[plr.Name] = tick()
else
print("Spam detected")
end
else
doClickThing(plr)
table.insert(PlayersLastTick,plr.Name)
PlayersLastTick[plr.Name] = tick()
end
end)
this should work
Looks good! I’m not even on my laptop but I can tell it works and detects spam clicks. Are you the creator? If you are, please explain briefly of the script so I won’t get incorrect understandings.
check if the player has been indexed to the table that stores the last tick of the players and then check if the difference between the current tick and the last tick is greater than or equal to the minimum seconds and if it is true, run the code and assign a new last tick for the next time the player clicks, if the player is not indexed, then, it means that it is the first time he clicks so we execute the code and create a new index for the player.