Following the Day/Night cycle tutorial, I decided to separate the statements that operate the Lamps from turning on and off depending on the day and the statements that cycles through Day and Night.
When I did that, the script doesn't work at all but it shows no error, there is nothing inside Script Performance either so I know it's not running.
The script is inside a part called "Lightpart" along with another child called "PointLight" which is a PointLight. The parent of Lightpart is a Model.
Lamp Operator... (Code that doesn't work)
if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then wait(1) script.Parent.Material = Enum.Material.Neon wait(1) script.Parent.PointLight.Enabled = true end if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then wait(1) script.Parent.Material = Enum.Material.Plastic wait(1) script.Parent.PointLight.Enabled = false end
Day/Night cycle... (Code that works)
lightPart = game.Workspace.Model.Lightpart minutesafterMidnight = 0 while true do minutesafterMidnight = minutesafterMidnight + 5 game.Lighting:SetMinutesAfterMidnight(minutesafterMidnight) wait(.1) end
As for why I chose to separate those two codes, it's because I notice that the codes do not run independently from each other so whenever I add in a debounce in the Lamp Operator, the Day/Night cycle stops for that rebound to.
1st code does not work because it is no looped. If you launch game with the time game.Lighting:GetMinutesAfterMidnight() == 18 * 60
it will do stuff, since server is started and time is not game.Lighting:GetMinutesAfterMidnight() == 18 * 60
it won't work. You should add the first code into while wait() do
loop :
while wait() do if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then wait(1) script.Parent.Material = Enum.Material.Neon wait(1) script.Parent.PointLight.Enabled = true if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then wait(1) script.Parent.Material = Enum.Material.Plastic wait(1) script.Parent.PointLight.Enabled = false end end