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 format a countdown like HH:MM:SS?

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

✓ Accepted answer

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).

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