I added a night/day cycle script to my game, and it is working very good. So, I decided to add a light column (that works with SpotLight). Then I added a script to the SpotLight, this script is supposed to make the spot light opens in night(19:00:00) and close after 600 seconds(5:00:00). But the script is not working, here is the script:-
Lighting.Parent.TimeOfDay:connect(function(Time)
if TimeOfDay = 19 then
SpotLight = true
while wait(600)
SpotLight = false
end
end
Here is the day/night cycle script if you want to know if it is wrong, note that I don't have troubles with this script:-
local dayLength = 24
local cycleTime = dayLength*60
local minutesInADay = 24*60
local lighting = game:GetService("Lighting")
local startTime = tick() - (lighting:getMinutesAfterMidnight() / minutesInADay)*cycleTime
local endTime = startTime + cycleTime
local timeRatio = minutesInADay / cycleTime
if dayLength == 0 then
dayLength = 1
end
repeat
local currentTime = tick()
if currentTime > endTime then
startTime = endTime
endTime = startTime + cycleTime
end
lighting:setMinutesAfterMidnight((currentTime - startTime)*timeRatio)
wait(1/15)
until false
NOTE: I am new to scripting, so you will find lots of mistakes.
Thanks for helping.

3 comments
Didn't work. I tried to put it in the part then put in the SpotLight itself and made some changes when it didn't work, I tried a lot of things but it is still not working. Try it yourself then edit your answer if it worked please. Thank you.
What didn't work? Were there errors or something going wrong?
I tried the script without changes as it is, when it didn't work I tried rewriting it. Here's what I found: 1)line 8, there shouldn't be ")" after "end" 2)There should be "then" somewhere in line 5 or 6. And is it even possible to make a light opens/closes at certain times?