I made this cooldown module, i think its realy nice but hey im still learning so tell me, is there something i should change/improve and how?
local Cooldowns = {}
local CooldownList = {
["Dash"] = 1.5,
["Lean"] = 0.2,
["LightAttack"] = 0.3,
["Block"] = 0.2,
}
function roundNumber(num, numDecimalPlaces)
return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
end
function Timer(Table,Cooldown)
local Time = tick()
repeat wait() until roundNumber((tick() - Time),1) == Table[Cooldown]
Table[Cooldown] = nil
end
local PlayersCooldown = {}
function Cooldowns:AddCooldown(Player,Cooldown)
if not PlayersCooldown[Player.Name] then
PlayersCooldown[Player.Name] = {}
end
PlayersCooldown[Player.Name][Cooldown] = CooldownList[Cooldown]
local thread = coroutine.create(Timer)
coroutine.resume(thread,PlayersCooldown[Player.Name],Cooldown)
end
function Cooldowns:CheckCooldown(Player,Cooldown)
if not PlayersCooldown[Player.Name] then
return false
end
if PlayersCooldown[Player.Name][Cooldown] then
return true
else
return false
end
end
return Cooldowns
yes I can
the task library is fairly new and it replaces spawn(), delay(), and wait()
that means they are getting deprecated and the new functions are task.spawn(), task.delay(), and task.wait()
more information on the library here
EDIT: task.defer() as stated is more of a replacement for spawn() and not task.spawn()