My timer is glitching out

For some reason, when my timer script goes past 1:00 minute, it glitches and starts counting a bunch of 9s and 0s.

How can I fix this?

local timerLabel = script.Parent

local runserv = game:GetService("RunService")


function setTime(Seconds) --thanks to D0RYU
	local SS = Seconds % 60
	local MM = (Seconds - SS) / 60 
	return MM..":"..(10 > SS and "0"..SS or SS)
end

runserv.Heartbeat:Connect(function()
	local song = workspace.chosenSong.Value


	local timer = (setTime(math.floor(((song.TimePosition*100)+0.5))/100) .. "/" .. setTime(math.floor(((song.TimeLength*100)+0.5))/100))
	timerLabel.Text = timer
	
	
	
	

end)

I have tried a few things but it still seems to not work.

Hey, I think I figured out the solution to your problem. Turns out you need math.floor() on the SS and MM too.

function setTime(Seconds) --thanks to D0RYU
    local SS = math.floor(Seconds % 60)
    local MM = math.floor((Seconds - SS) / 60)
    return MM..":"..(10 > SS and "0"..SS or SS)
end

And keep it here as well?

Blockquote local timer = (setTime(math.floor(((song.TimePosition*100)+0.5))/100) .. "/" .. setTime(math.floor(((song.TimeLength*100)+0.5))/100))

Yeah that part was fine when I tested it.

Thank you so much! It works very well, finally.

Have a great day!

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