Timer countdown doesn't have a 0 when reaching ones digits?

Hi…
I’ve been trying to achieve a system where I convert a raw integer countdown into a minutes:seconds system. It works fine, but when the timer’s seconds reaches below 10, I don’t know how to add a zero before the number.

Here’s what I mean
Time before seconds go into single digits

Timer when seconds go into single digits

How could add a zero when the seconds go into single digits?

My current code

while true do
local ms = workspace.Time.Value
script.Parent.Text = math.floor(ms / 60)…“:”… (ms % 60)
wait()
end

You would have to add the 0 manually with the code.

Try this:

while true do
    local ms = workspace.Time.Value
    local seconds = (ms % 60) < 10 and "0"..(ms%60) or (ms%60)
    script.Parent.Text = math.floor(ms / 60)..":" ..seconds
    wait()
end
3 Likes

For the hours, minutes, seconds, etc. you can use the code below:

string.format("%02i", NUMBER HERE)
3 Likes

you can use this function @posatta made in a different thread:

local function format(num, digits)
	return string.format("%0" .. digits .. "i", num)
end

In this case the number of digits you want is 2.

1 Like

This works perfectly and stills follow my code! Thank you!