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

How do I format a countdown like HH:MM:SS?

Asked by
YTWolFs 11
3 years ago

Hello! How do I make so that this countdown script formats the text in Hours:Minutes:Seconds instead of just seconds?

local GUI = script.Parent
local ClickDetector = game.Workspace.CDStart.ClickDetector

ClickDetector.MouseClick:Connect(function(clicked)
    for i = 120, 0 , -1 do
        GUI.Text = i
        wait(1)
    end
end)

1 answer

Log in to vote
0
Answered by 3 years ago

Not in the mood to explain, here's a way to get the format from a number.

function totime(number)
    local hours, minutes, seconds
    hours = math.floor(number / 3600); number -= hours * 3600
    minutes = math.floor(number / 60); number -= minutes * 60
    seconds = number

    if hours < 10 then hours = "0"..hours end
    if minutes < 10 then minutes = "0"..minutes end
    if seconds < 10 then seconds = "0"..seconds end

    return hours..":"..minutes..":"..seconds
end

Put it at the top of your script, and on line 06 do Gui.Text = totime(i).

Ad

Answer this question