How can i make a clock?

I want to make a clock for my day night cycle and i do know how to make one sorta but it includes the seconds which i do not want.

How can i only have the hours and minutes for a clock?

Is it a real-time clock or based off of the server?

1 Like

A clock that goes off the ingame day night cycle.

You’ll wanna do something like this, assuming you already have a script that gradually changes the TimeOfDay value in lighting.

local timeOfDay = game.Lighting.TimeOfDay
local textLabel = yourGui -- Set this to whatever GUI you want to display the time

while true do
  textLabel.text = string.sub(timeOfDay, 1, 2) .. string.sub(timeOfDay, 3, 4) -- or 5, 6, it depends if the semicolon is included.

This script will update the time on the GUI every 1 second.

Now normally this would work, however, I’m not sure if string.sub can read values from the Lighting.

Small typo, commas should be after both timeOfDays.

Fixed, thanks for calling that out.

1 Like

Using while true loops in that fashion is a bad practice; use Instance::GetPropertyChangedSignal() instead.
This is assuming all the code you wrote was functioning.

local textLabel = yourGui

textLabel.Text = string.sub(game.Lighting.TimeOfDay, 1, 2) .. string.sub(game.Lighting.TimeOfDay, 3, 4) -- or 5, 6, it depends if the semicolon is included.