Cooldown frame isn't correctly being sized

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:

The code:


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. :wave:

1 Like

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)

Let me quickly check and modify everything, I’ll post more if help is needed.

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.

Turns out I just need to do “i/cooldown” in order to get the decimals. Although, I appreciate your help! Without your help I would’ve figured it out!

So you’re marking your post as the Solution using the exact code I suggested at the end of my first post?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.