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

How do i make a counddown timer in a Gui from text?

Asked by 7 years ago

So, i know a way to make a timer the only way, but the one i want goes for 5 mins. I can type 5 mins. (script.Parent.Text = '4:59I would have to do that but lower the number is the harder way.) of a certain code over, and over, and over again! Can someone help me?

0
There's multiple ways of doing it. Depending on your game, really. But one thing you don't want to do is '4:59' -- You can use a for loop though, that would go for 300 seconds iamnoamesa 674 — 7y

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

You can use the Modulus operator for this. %

The Modulus operator takes the remained and removes it from the input. 63%60 would be 60 + 3 remaining, so it returns 3.

5 minutes would be 300 seconds. (Or just do 60*5)

To get rid of the "4:10", "4:9", "4:8" i do tostring("0"..math.floor(i%60)):sub(-2). This forms the numbers to a string and takes the last 2 values from it, giving you 04:10, 04:09, 04:08

A countdown timer would look like this:

for i=300,0,-1 do
    local Minutes =  tostring("0"..math.floor(i/60)):sub(-2)
    local Seconds = tostring("0"..math.floor(i%60)):sub(-2)
    TextLabel.Text = Minutes..":"..Seconds
    wait(1)
end
0
Thats good! Thank you! Chez_Guy 67 — 7y
Ad

Answer this question