Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Making a countdown GUI display minutes left? [Solved]

Asked by 9 years ago

I'm attempting to have a countdown GUI for my game display how many minutes are remaining and removing the colon to display the remaining seconds after 2 minutes have past.

local countdown = 1
    for countdown = 120, 0, -1 do
    wait(0.1)
    TimeNumbers.Text = ":" ..countdown
    if TimeNumbers.Text "" then
        TimeNumbers.Text = ""..countdown
    end
    wait(1)
end

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
9 years ago
for countdown=120,0,-1 do
    if countdown>=60 then
        TimeNumbers.Text=math.floor(countdown/60)..':'..('0'..(countdown%60)):sub(-2)
    else
        TimeNumbers.Text=countdown
    end
    wait(1)
end

This will display time time as minutes:seconds until 1:00, then it will count down from 59. ('0'..(countdown%60)):sub(-2) makes sure that the seconds are always two digits, by adding a '0' in front.

Ad

Answer this question