I wanna stop exploiters from spamming databases and remote events in a while loop, so I’m thinking of implementing a cooldown system, though the problem is I’m not sure how to do it. I have a feeling it’s supposed to do with os.time(), but I’m not sure how
You can just set a bool value associated with each player
local PlayerCoolDowns = {} -- make a table to store all the player's cooldowns
game.Players.PlayerAdded:Connect(function(Player)
PlayerCoolDowns[Player.UserId] = false -- add the player to the table when they join
end)
RemoteEvent.OnServerEvent:Connect(function(Player) -- on event
if PlayerCoolDowns[Player.UserId] == false then -- check if they have no cooldown
PlayerCoolDowns[Player.UserId] = true -- change their cooldown
--do something
wait(cooldown) -- waits for the cooldown to finish
PlayerCoolDowns[Player.UserId] = false -- finishes the cooldown
end
end)
2 Likes
Thanks for the starter, I totally forgot about using arrays for storing stuff
1 Like