Hello! I’ve been trying to make a frame that gets sized based on the cooldown left on the tool’s cooldown, like in the “Strongest Battlegrounds”, which as you can see by now, I’m having trouble with.
Whenever I use the tool, instead of being sized properly, its like this:
local function getAbilityHotbar()
local foundTool = nil
if player.PlayerGui.Hotbar:FindFirstChild("Holder"):FindFirstChild(tool.Name) then foundTool = player.PlayerGui.Hotbar:FindFirstChild("Holder"):FindFirstChild(tool.Name) end
return foundTool
end
local function startCooldown()
coroutine.wrap(function()
isonCooldown = true
for i=cooldown, 0, -0.01 do
wait()
currentCooldown = tostring(math.round(i))
local foundBar = getAbilityHotbar()
foundBar.CooldownFrame.Size = UDim2.new(1,0, -currentCooldown/5, 0)
end
isonCooldown = false
end)()
end
-- More code... (the rest of it isn't really important.)
How can I fix this issue, or is there any alternative methods to achieve what I’m trying to get?
Help would be appreciated a lot. Thanks.
math.round only rounds to whole numbers (integers).
If it absolutely has to be an integer then make your for i=cooldown, 0, -.01 do
line something like for i = (cooldown * 100), 0, -1 do
Then why are you making currentCooldown a string (text) and rounding it anyway?
You could just get rid of that line and have your first setup
for i=cooldown, 0, -0.01 do
-- code
foundBar.CooldownFrame.Size = UDim2.new(1,0, -cooldown/5, 0)
But you’d have to modify the other value to divide i by 100 to get your proper decimal value for the cooldown. foundBar.CooldownFrame.Size = UDim2.new(1,0, -currentCooldown/500, 0)
which divides by 5 and 100 at the same time to make i into a decimal.