AM and PM Time GUI

Hello… I’m trying to achieve a time GUI.

No this doesn’t take long since it’s only with time of day but I have something different…

Instead of it being like 10:32 I want it to be

10Pm (depends on day or night)

Can anyone help me

I think you could just change it’s AM, PM Text Label after every 43200 seconds. (43200 seconds = 12 hours) or actually I am sorry according to whatever time your game needs I am sorry.

Sorry I forgot to correct myself.

I meant I want it to be like

Do you want it that at after a certain time period?


I need to use a day/night cycle and connect through the time of day
I need to use some variables I’m pretty sure. So if it were 1:45 in time of day
It would show up either 1am or 1pm

You could use 24 hour timer (there’s ClockTime property in Lighting) and then get AM/PM simply by doing this

local suffix = time <= 12 and "AM" or "PM"

In order to remove decimals you could use string patterns to only mach out the number before period or simply calling math.floor(Lighting.ClockTime).


The time is a string “00:00:00” if the time is 1AM it would be “01:00:00” 1PM would be “13:00:00” since it uses military time.

If you split the Lighting.TimeOfDay string at the colons and then check if the first number is over 12 you subtract 12 and set it to display PM instead of AM.

I don’t understand where I put it… so I use a free modelers gui timer. Where do I put that

Source : Trying to get am/pm based on TimeOfDay

	local Hours = tonumber(string.sub(Lighting.TimeOfDay, 1, 2)) -- Gets the hours, turns 05 --> 5
	local Minutes = string.sub(Lighting.TimeOfDay, 4, 5) -- Gets the minutes, keeps the extra 0
	local String = '%s:%s %s'
	if Lighting.ClockTime >= 13 and Lighting ~= 0 then -- It's between 1pm and 11:59pm
		String = String:format(Hours - 12, Minutes, 'pm')
	elseif Lighting.ClockTime >= 12 and Lighting.ClockTime < 13 then -- It's between 12pm and 12:59pm
		String = String:format(Hours, Minutes, 'pm')
	elseif Lighting.ClockTime >= 0 and Lighting.ClockTime < 1 then -- It's between 12:00am and 12:59am
		String = String:format(12, Minutes, 'am')
	else -- It's between 1:00am and 11:59 am
		String = String:format(Hours, Minutes, 'am')
	timer.Text = String

Only difference is that you don’t want the minutes, so just remove anything minute related.


Thank you, this would change the label for the GUI correct ?

on a GUI, “TextLabel” have the properties “Text”, and as you can see in the example sent,
we converted the time into a String, then apply the information in the TextLabel :

timer.Text = String

This is a normal script correct, I don’t want to get it wrong.

Regular scripts don’t run on client.

1 Like

Oh i didn’t get your question until rokec123 mentions it,

This is a Localscript for the Client, because any change to the Lightning is replicated to the player anyways.

To be precise, this code will start everytime the properties “ClockTime” is changed :
Which is a object that can be seen from the server or the client.

Do I put that in lighting or in the GUI?

GetPropertyChangedSignal is an event that fires once given property changes, so in the case shown above, you are connecting it to a function which will run once the event fires, so yes, this goes in the local script located in your gui.

It’s on top of the script though. I don’t get why it isn’t working…

Are there any errors; if so, what are they? Would you mind showing me your entire code?

I’m using the code sent to me,
19:04:00.871 - Players.CrunchyRBLX.PlayerGui.ScreenGui.TextLabel.LocalScript:1: attempt to index nil with ‘GetPropertyChangedSignal’

19:04:00.872 - Stack Begin

19:04:00.872 - Script ‘Players.CrunchyRBLX.PlayerGui.ScreenGui.TextLabel.LocalScript’, Line 1

19:04:00.873 - Stack End

Is the output

1 Like
local Lighting = game:GetService('Lighting')
local State = "AM"

	if Lighting.ClockTime < 12 then
		State = "AM"
		State = "PM"

Just copy that, that’s how you get AM/PM then you can put it in your string.

1 Like