Alarm clock time not working

My alarm clock for my game is not working, it has a text label called time and for some reason the clock doesnt work and the time of day doesnt change. Can anyone fix this? Thanks!

local Gui = script.Parent.Time

	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 = "PM"
	else
		period = "AM"
		hours -= 12
	end
		if hours == 0 then
		hours = 12
	end
		return string.format("%02d:%02d %s", hours, minutes, period)
	end

while true do
	Gui.Text = getLightingTime()
	wait()
end

is code located in server script?
does console output anything?

code is located in server script and does not output anything.

examined your code, cant find a problem in it honestly, have you tried debugging it? try testing the game and open properties to check if the text is actually updating or it just wont display.
are you using surface gui and is the alarm located in the workspace? because it also might seem that the script is just not being executing at all
P. S. i really need to go and if this remains unsolved ill come back tmrw

the text wont display and nor does the time on the lighting and its a surface gui on the clock in the workspace

There’s nothing wrong with the script itself, you’re probably not updating the text due to your variable Gui being incorrect and misassigned.

oh sorry, my bad, just realized that you wrote the time was not changing, it’s because you can do daynight cycle only via a script.
try putting this one in workspace as a server script

-- time changer
local mam --minutes after midnight
local timeShift = 3.2 --how many minutes you shift every "tick"
local waitTime = 1/30 --length of the tick

while true do
     --time changer
     mam = game.Lighting:GetMinutesAfterMidnight() + timeShift
     game.Lighting:SetMinutesAfterMidnight(mam)
     mam = mam/60

     --tick
     wait(waitTime)
end

try editing this one on how it suits you
please mark this as solution if i helped you :smiley:
p. s. if you want to have a somewhat smoother cycle this guide can help you A Guide to a Better Looking and More Realistic Day/Night Cycle

1 Like

Thanks so much! It goes by an hour every second lol but I can fix it

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.