Creating a digital clock

I am currently trying to make a clock with this type of format:
Screenshot 2020-04-20 at 8.31.53 AM

Currently my script runs very well, except when I get down to the single digit numbers (9, 8, 7, etc.), the clock says 0:X instead of 0:0X and I don’t know how to add a zero for only 1 digit numbers.

Also, if I wanted to make a minute, such as 1:30, how would I make it so it would take away a minute every 60 seconds?

Script is below:

local roundLength = 10
local intermissionLength = 30

local replicatedStorage = game:WaitForChild("ReplicatedStorage")
local roundPhase = replicatedStorage.RoundPhase
local roundTimer = replicatedStorage.RoundTimer
local inRound = replicatedStorage.InRound

local function phase()
while wait() do
	for i = intermissionLength, 1, -1 do
		inRound.Value = false
			wait(1)
		roundPhase.Value = "Phase: Intermission"
	end
	for i = roundLength, 1, -1 do
		inRound.Value = false
			wait(1)
		roundPhase.Value = "Phase: Round"
	end
end
end

local function timer()
while wait() do
	for i = intermissionLength, 1, -1 do
		roundTimer.Value = "0:" .. i
		wait(1)
	end
end
end

Thank you very much in advance.

If you want to have two digits show up instead of one when it is less than ten, you can do this:

if Seconds < 10 then
  Seconds = "0"..Seconds
end

Basically, it sticks a zero before the second count, whenever it is less than ten to retain two digits.

Just do "0:" .. string.format("%002d", i). string.format with %d as its formatter. (I think it’s called a formatter, but I’m not entirely sure on the terminology.) %d will automatically pad it with 0s (or whatever the first character happens to be) until it’s the same number of characters as your number (which are the second two characters).

(Edit because my grammar was a mess)

5 Likes