TimeOfDay doesn't change

Well, I made simple while loop which changes game.Lighting.TimeOfDay to 1 second forward.
The issue is that my loop stops working after 5-10 times of activation. Loop works for 10 seconds and then stops working.
Here is my code:

while true do
    game.Lighting:SetMinutesAfterMidnight(game.Lighting:GetMinutesAfterMidnight()+1/60)
    wait(1)
end

Try this.

local Time = 0
local Speed = 10

while true do
	Time = (Time + 1)%1440
	game.Lighting:SetMinutesAfterMidnight(Time)
	wait(1/Speed)
end

Time will change by variable Time.
I haven’t tried this script yet, so use variable Speed for debugging. (Multiplier of speed)
You can delete variable Speed and replace wait(1/Speed) to wait(1).

2 Likes

Thanks for your solution. Unlike my method - it doesn’t stop working.

1 Like