Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to add 0 to a single digit countdown timer?

hi there, I had a timer script that will output a timer like this screenshot.

here is the code.

 for i = GameLength, 0, -1 do
        local minutes = math.floor(i / 60)
        local seconds = i - (minutes * 60)
        Status.Value = (minutes..":"..seconds)
        wait(1)
    end

so my question is how to make the timer more intuitive by adding a 0 after counting down from 10. like this screenshot.

thanks

1 answer

✓ Accepted answer

This has been covered many times, e.g. in this thread on the devforums.

Essentially, you can use the string.format function to format the seconds string padded with 0s to a specific width, e.g.

for i = 101, 1, -1 do print(string.format( "%.3i", i )) end

prints the numbers from 101 to 1 padded with 0s to a width of 3 (indicated by the number between '.' and 'i', so e.g. 54 becomes 054 and 3 becomes 003.

1 comment

0

thanks for the answer. it works.

This discussion is preserved as it was. New answers, comments, and votes are closed.