Global cool down on something

How can I make a saving cool down for something?

E.I Bob pushes a button, leaves the server, and joins back, but since he has a cool down for pushing the button, he isn’t able to until X amount of time is up?

Basically, how can I make a cool down for pushing the button, where it saves, even if the player d/c’s.

Would I have to use SQL or something?

It’s quite easy, you don’t need sql (except if the cooldown should persist after server restart, but I guess you don’t want it this way).

Just make a new table where you can save such informations.
Eg:



-- initialize the table, one time in your script.
playercooldowns = {}

-- write your cooldown this way
playercooldowns[player:SteamID64()] = 60
-- you can of course also access it this way
print(playercooldowns[player:SteamID64()])


You also have to implement something which counts it down etc. But I guess you know how to do it. Basically make a timer which triggers every 1 sec (depends on the resolution you want), and subtract then 1 from all values in the table by iterating through the table. You can later check then if playercooldowns[player:SteamID64()] is > 0



playercooldowns = {}
local CooldownDuration = 60 --In seconds
playercooldowns[player:SteamID()] = CurTime() + CooldownDuration

if CurTime() > playercooldowns[player:SteamID()] then
--Cooldown ended
else
--Cooldown active
end


Not tested, i think this is better than with timer.