Why is my tween not equivalent to my for loop?

When I tween the cooldown bar to shrink and make a for loop in order to decrease the cooldown counter, the cooldown bar shrinks before the counter reaches zero. I’m trying to make both of them last 7 seconds.

this is what happens in game

Code:
(this isnt my entire code, its just the part i want to highlight)

local cooldown = 7

local cooldownBarInfo = TweenInfo.new(
	cooldown,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local function cdCountdown()
	moveSlotCooldownCounter.Visible = true
	for i = cooldown, 0, -0.1 do
		moveSlotCooldownCounter.Text = string.format("%.1f", i)
		task.wait(0.1)
	end
	moveSlotCooldownCounter.Visible = false
end

local cooldownBarShrinkTween = TweenService:Create(moveSlotCooldownBar, cooldownBarInfo, {Size = UDim2.new(1, 0, 0, 0)})
moveSlotCooldownBar.Size = UDim2.new(1, 0, 1, 0)
cooldownBarShrinkTween:Play()
cdCountdown()

Actually, all you have to do is create another tween statement for the seconds value. Tween service does IN FACT support the numbers too! Just not string values. I wish.

local cooldown = 7

local cooldownBarInfo = TweenInfo.new(
	cooldown,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)

local function cdCountdown()
	moveSlotCooldownCounter.Visible = true
	for i = cooldown, 0, -0.1 do
		moveSlotCooldownCounter.Text = string.format("%.1f", i)
		task.wait(0.1)
	end
	moveSlotCooldownCounter.Visible = false
end

local cooldownBarShrinkTween = TweenService:Create(moveSlotCooldownBar, cooldownBarInfo, {Size = UDim2.new(1, 0, 0, 0)})
moveSlotCooldownBar.Size = UDim2.new(1, 0, 1, 0)

task.spawn(function()
	cooldownBarShrinkTween:Play()
end)

task.spawn(function()
	cdCountdown()
end)

Because they’re both being initiated at different starting times, you can create multiple threads to ensure both are executed within a similar time difference of one another.

same result, the bar shrinks before counter reaches 0

sorry i dont completely understand what you mean by this

Weird, for whatever reason your for loop must be taking longer than 7 seconds, I’m guessing that’s because task.wait(0.1) isn’t exactly 0.1 seconds or there’s some lag present in your game.