My Day/Night script somethings wrong

I want make Day/Night Loops script but it cant do night!

daynightscriptwrong
from this gif, day is working but night script cant working
This script

while wait(2) do
	print("day")
	for i = 3,15,0.1 do
		game.Lighting.ClockTime = i
		wait(0.000001)
	end
	wait(2)
	print("night")
	for v = 15,3,0.1 do
		game.Lighting.ClockTime = v
		wait(0.000001)
	end
end

maybe must use free script from toolbox if cant fix this script

2 Likes

Oh, this is because of your for loop. Do something like this:

minaftermid = 0
while wait(.1) do
	minaftermid = minaftermid + 1
	game.Lighting:SetMinutesAfterMidnight(minaftermid)
end

I haven’t tried this yet but it should work. Let me know if there is any other problems.

So i edited your script and here it is:

while wait(2) do
	print("day")
	for i = 3,15,0.1 do
		game.Lighting.ClockTime = i
		wait(0.000001)
	end
	wait(2)
	print("night")
	for v = 15,24,0.1 do -- changed 15,3 to 15, 24
		game.Lighting.ClockTime = v
		wait(0.000001)
	end
	for a = 0,3,0.1 do -- Added a new for loop
		game.Lighting.ClockTime = a
		wait(0.000001)
	end
end

2 Likes

Don’t write wait(0.000001), wait() is already the lowest number.

I know but I, just wanted to make it work, so the wait dont really bother me

1 Like