How would I create a 12AM - 6AM system

I’ve looked everywhere for an answer to this but couldn’t find anything.

I know you can just make a 12am-6am system using plain wait()s but theres gotta be a better way to do it. Help would be greatly appreciated.

Edit: Looks like some people didn’t understand what I meant. I want to have a GUI go from 12am to 6am, not the actual time. Not sure how exactly I should do this, but here was one of my attempts.

-- i dont feel like writing the countdown but basically I just had a countdown for 270

local times = {
TwelveAM = 250,
OneAM = 220,
TwoAM = 190,
-- etc}

   if table.find(times, countdown.value) then
-- do whatever

But I’m not sure.

while true do
	local TimeInUnix = os.time()
	local Date = script.Parent
	local stringToFormat = "%I:%M %p"
	local result =, TimeInUnix)
	Date.Text = result

i think this should work

  1. Clock Script Parented to a TextLabel:
local Gui = script.Parent

function getLightingTime()
	local totalMinutes = game.Lighting:GetMinutesAfterMidnight()
	local hours = math.floor(totalMinutes / 60)
	local minutes = math.floor(totalMinutes % 60)
	local period
	if hours < 12 then
		period = "AM"
		period = "PM"
		hours -= 12
	if hours == 0 then
		hours = 12
	return string.format("%02d:%02d %s", hours, minutes, period)

while task.wait() do
	Gui.Text = getLightingTime()
  1. Daylight Cycle Script Parented to Workspace:
local dayLength = 45 --// In minutes — feel free to change this.

local cycleTime = dayLength*60
local minutesInADay = 24*60

local lighting = game:GetService("Lighting")

local startTime = tick() - (lighting:getMinutesAfterMidnight() / minutesInADay)*cycleTime
local endTime = startTime + cycleTime

local timeRatio = minutesInADay / cycleTime

if dayLength == 0 then
	dayLength = 1

	local currentTime = tick()

	if currentTime > endTime then
		startTime = endTime
		endTime = startTime + cycleTime

	lighting:setMinutesAfterMidnight((currentTime - startTime)*timeRatio)
until false

I did not create these scripts, these are some I had laying around that I picked up from the DevForum.


If someone could please rereply to this that’d be nice (post boost)


This should work:

secondTime = what time it is
hourTime = nil

while true do
      time += 1
      hourTime = (math.floor(secondTime/(60*60)))

i havent tested it though since i dont wanna open up studio


oh and

if hourTime > 6 and < 12 then

or vice versa

1 Like

Can you be more clear with this line? You want a GUI clock or what?

In your second Script, you have a startTime, but it uses tick(), but let me tell you that tick is the time in seconds since 1 January 1970, so can you explain what you did in that line? Because for me, it’s too confusing.

1 Like

wrong, the script basically fetches the game time and displays it, tick() is every second in a roblox game iirc, not unix timestamp

the script will display the time as 06:00 AM if the clock time is 06:00:00 or game time is 6

1 Like

You may see here what tick() is.

1 Like

yeah but that has nothing to do with the script i sent

it does what i said it does, it does NOT display the current # of seconds since 1/1/70

1 Like

But I don’t get like why are you subtracting the no. of seconds from the tick()? Like tick() is a huge no. so subtracting from it doesn’t make any sense to me atleast. That’s why I asked for a clear explaination so I learn about what you did.

1 Like

what is your point dude?

it works fine, test it if you want to

1 Like

This is what I’m trying to say.

1 Like

I didn’t mean that the script would show that time. I’m not that dumb. I mean why you added tick()? It is the no. of seconds since 1/1/1970

1 Like

How is tick() a huge no? if anything this is the most efficient way to make the clock system work.

1 Like

Read the post before you reply to it buddy.

1 Like

So you should atleast give credits. Also you should atleast know what is the script doing rather than just posting :slight_smile:

Btw tick() is a huge no. because it’s literally the no. of seconds since 1/1/1970, I even linked a post about it above.

(Don’t think I got toxic buddy. I’m just here to learn new things and help people.)

1 Like
  1. I do not know where I got it from, just that it is off of devforum
  2. I literally know exactly what the script does, you have web developer in your title so im assuming you know little to nothing about specific roblox coding, i told you what it does

and before you question, i have 2y of experience

1 Like

Hmm, if you are really 2 years experienced, then you should have known that what exactly tick() is. And it will be really good for “beginners” like me if you explain that specific line of code. Like what you did exactly there. See I’m not here to fight but to learn.

1 Like