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
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
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