When I run my game, the loop presented below works properly and it prints tick as intended, the issue is that around the 00:00:05 area of the TimeOfDay, it constantly stops. The moment I change the time to 02:00:00 then it updates perfectly fine seemingly all the way up to 00:00:05 again. What is causing this?
Yeah I ran that code in my game too and it froze after some time. What would be better is if in the loop you get the elapsed time between the current iteration and the last. Then you would multiply the elapsed time by the cycle speed. I’m not completely sure why that one doesn’t work as I don’t use lighting often but I find that this works:
local EnvironmentHandler = {}
local Lighting = game:GetService("Lighting")
local DayNightCycleSpeed = 100
local DelayTickSpeed = 1/DayNightCycleSpeed
EnvironmentHandler.DayNightCycle = function()
local lastTime = tick()
while task.wait(DelayTickSpeed) do
local now = tick()
local delta = now - lastTime
lastTime = now
local CurrentTime = Lighting:GetMinutesAfterMidnight()
Lighting:SetMinutesAfterMidnight(CurrentTime + (delta * DayNightCycleSpeed))
end
end
return EnvironmentHandler