Hello, everyone! I thought I would share this simple module I created a long time ago which helps manage skill cooldowns on the server side. It requires knowledge on Data Tables, Remote Events, Module Scripts, and Control Flow.
The guide I wrote isn’t that good, but I just wanted to post this for anyone who might find it useful somehow.
local cooldowns = {}
local active = {}
function cooldowns:Set(cd, _time)
cooldowns:Clr(cd)
active[cd] = task.delay(_time, function()
active[cd] = nil
end)
end
function cooldowns:Has(cd)
return active[cd]
end
function cooldowns:Clr(cd)
if (active[cd]) then
task.cancel(active[cd])
end
end
return cooldowns
this is what i use for my game (for the client side- the server side i havent done yet but would creating cooldown ‘objects’ which have their own active cooldowns array and assigning it to each player)
this is my server implementation i havent tested it yet
local cooldowns = {}
cooldowns.__index = cooldowns
function cooldowns.New()
return setmetatable({}, cooldowns)
end
function cooldowns:Set(cd, _time)
cooldowns:Clr(cd)
self[cd] = task.delay(_time, function()
self[cd] = nil
end)
end
function cooldowns:Has(cd)
return self[cd]
end
function cooldowns:ClrAll()
for k in next, (self) do
task.cancel(self[k])
self[k] = nil
end
end
function cooldowns:Clr(cd)
if (self[cd]) then
task.cancel(self[cd])
end
end
function cooldowns:Destroy()
self:ClrAll()
setmetatable(self, nil)
end
return cooldowns
np
scrap the client side one
on both side just make a cooldown object and destroy & recreate it every time the players character loads cuz every time the player respawns all their cooldowns would be gone which is what you want