I have recently made a cooldown system, but have ran into an issue where if there are multiple cooldowns running, the last one will always break. Even when I print the framename and cooldown name, it is giving the right name, but the last cooldown still breaks.
I suspect this is because it is removing the wrong tables, but I am not sure.
Here is an example with gyazo
https://gyazo.com/09c2823931847e358159a80336e6f2d2
Code for the function:
local activecds = {}
local activeframes = {}
local function cooldown(player, numtime, name)
coroutine.resume(coroutine.create(function()
local cdframe = player:WaitForChild("PlayerGui"):WaitForChild("CDs"):WaitForChild("Frame")
if not activecds[name] then activecds[name] = name
if numtime <= 0 then
activecds[name] = nil
return
end
local cd = game.ReplicatedStorage.Stuff.CD:Clone(); cd.ImageLabel["CDName"].Text = name; cd.ImageLabel.CD.Text = tostring(math.floor(numtime*10)/10); cd.Name = name; cd.Parent = cdframe
table.insert(activeframes, {name, cd})
else
local cd = nil
for i,v in pairs (activeframes) do
if v[1] == name and activecds[name] then
cd = v[2]
name = activecds[name]
if cd.Name ~= name then
cd = nil
end
break end
end
if cd == nil or name == nil then return end
if numtime <= 0 then
local framename = cd.Nameactivecds[name] = nil; table.remove(activeframes, table.find(activeframes, {framename, cd})); cd:Destroy();
print(framename, cd)
return end
cd.ImageLabel["CDName"].Text = name; cd.ImageLabel.CD.Text = tostring(math.floor(numtime*10)/10); cd.Parent = cdframe
end
end))
end