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

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

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?

1 comment

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

1 answer

✓ Accepted answer

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

1 comment

0

Thats good! Thank you!

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