Hello! How do I make so that this countdown script formats the text in Hours:Minutes:Seconds instead of just seconds?
1 | local GUI = script.Parent |
2 | local ClickDetector = game.Workspace.CDStart.ClickDetector |
3 |
4 | ClickDetector.MouseClick:Connect( function (clicked) |
5 | for i = 120 , 0 , - 1 do |
6 | GUI.Text = i |
7 | wait( 1 ) |
8 | end |
9 | end ) |
Not in the mood to explain, here's a way to get the format from a number.
01 | function totime(number) |
02 | local hours, minutes, seconds |
03 | hours = math.floor(number / 3600 ); number - = hours * 3600 |
04 | minutes = math.floor(number / 60 ); number - = minutes * 60 |
05 | seconds = number |
06 |
07 | if hours < 10 then hours = "0" ..hours end |
08 | if minutes < 10 then minutes = "0" ..minutes end |
09 | if seconds < 10 then seconds = "0" ..seconds end |
10 |
11 | return hours.. ":" ..minutes.. ":" ..seconds |
12 | end |
Put it at the top of your script, and on line 06 do Gui.Text = totime(i)
.