Day/Night script with while true do loop not breaking

Im trying to make a Day/Night script with a while true do loop but it’s not working.

What im trying to do is if the ClockTime = 9 or < 19 then it adds 0.1 to the clocktime every 2 minutes, and if it’s bigger than 19 or smaller than 9 it takes 30 seconds to add 0.1 to the clock time but whenever the Clocktime is at 19 it stops.

I couldnt find anything on the internet about this issue.

Here’s my script:

 local lighting = game:GetService("Lighting")

local starttime = 9

lighting.ClockTime = starttime

while true do
	if lighting.ClockTime >= 9 and lighting.ClockTime <= 18 then
		lighting.ClockTime = lighting.ClockTime + 0.1
		wait(120)
	elseif lighting.ClockTime >= 19 and lighting.ClockTime <= 9 then
		lighting.ClockTime = lighting.ClockTime + 0.1
		wait(30)
	end
	wait()
end```


What I think is happening is, when the script gets to the elseif line the loop stops, idk why its not working, and there are no errors in the output tab.
1 Like

Probably due to how your logic is set up, ClockTime cannot be greater or equal to 19 and be less than or equal to 9 at the same time

First, there is no reason to add “and” to both of the if statement. Since it’ll do that when it >= 19 or >= 9. Second, tell me the error in output.

2 Likes