How to make a timer

i want to make a timer that displays time like: 3:00AM and every 8 seconds it will go up by one: 3:01AM
I am amare this could use tick() or some string however i dont know how to use those.

local hours = 3
local minutes = 0
local LastTimerAdvance = tick()

game:GetService("RunService").Heartbeat:Connect(function ()
    if tick() - LastTimerAdvance > 8 then
        LastTimerAdvance = tick()
        minutes = minutes + 1
        if minutes >= 60 then
            minutes=  0
            hours = hours + 1
        end
        if hours >= 24 then
             hours = 0
        end
    end
end)
2 Likes

Try this, it is a 24 hours clock system, i wrote it on my phone. Lmk when it does not work

1 Like

Visualization is your job, I cannot help you there.

I am more asking for how I can display 3:00, 3:01, 3:10 on a TextLabel or just printing; print(Time)
3:00

gui.Frame.TextLabel.Text = ToString(Time) try something like that but with the vairables filled in

1 Like

you could also do

 TextLabel.Text = ToString(Time) .. ":" .. Time2

or whatever you need.

I am more asking for how I can display 3:00, 3:01, 3:10 on a TextLabel or just printing; print(Time)
3:00

A better example is the watch in The Rake

Are you asking for something similar to this?

function Format(Int)
	return string.format("%02i", Int)
end

function convertToMS(Seconds)
	if Seconds < 3600 then
		local Minutes = (Seconds - Seconds%60)/60
		Seconds = Seconds - Minutes*60
		return Format(Minutes)..":"..Format(Seconds)
	else
		local Minutes = (Seconds - Seconds%60)/60
		Seconds = Seconds - Minutes*60
		local Hours = (Minutes - Minutes%60)/60
		Minutes = Minutes - Hours*60
		return Format(Hours)..":"..Format(Minutes)..":"..Format(Seconds)
	end
end

print(convertToMS(300)) -- 300 seconds = 5 minutes
print(convertToMS(480)) -- 8 minutes
print(convertToMS(1500))
print(convertToMS(5000))

Output:

05:00
08:20
25:00
01:23:20
local hours = 3
local minutes = 0
local LastTimerAdvance = tick()
local Textlabel = script.Parent -- Your path here

function GetTimeDisplay(h, m)
    if m < 10 then
        m = "0" .. tostring(m)
    end
    if h < 10 then
        h = "0" .. tostring(h)
    end
    return tostring(h) .. ":" .. tostring(m)
end

game:GetService("RunService").Heartbeat:Connect(function ()
    if tick() - LastTimerAdvance > 8 then
        Textlabel.Text = GetTimeDisplay(hours, minutes)
        LastTimerAdvance = tick()
        minutes = minutes + 1
        if minutes >= 60 then
            minutes=  0
            hours = hours + 1
        end
        if hours >= 24 then
             hours = 0
        end
    end
end)
1 Like
TextLabel.Text = hour .. ":" .. minute

you could run the clock script from when server starts and make it update a value in replicated storage scripts can get the time from and do something like what I said above.