This script is scripting point-lights in a brick. I would like it to turn off during the day, but I can't seem to combine the scripts overall. I think I'm missing a variable or I have the wrong variable. This script is for individual runway lights. Each light has to blink at different times. If you can, don't mess with the timing system, because that works correctly, my issue is adding turn off during day time hours.
while(wait())do local l = game.Lighting:GetMinutesAfterMidnight()/60 -- Get hours after midnight :3 script.Disabled = l>6 or l<18 -- If it's before 6AM, or after 6PM turn it on end if script.disabled == true then script.Parent.Light1.PointLight.Enabled = true wait(0.001) script.Parent.Light1.PointLight.Enabled = false wait(0.001) script.Parent.Light2.PointLight.Enabled = true wait(0.001) script.Parent.Light2.PointLight.Enabled = false wait(0.001) script.Parent.Light3.PointLight.Enabled = true wait(0.001) script.Parent.Light3.PointLight.Enabled = false wait(0.001) script.Parent.Light4.PointLight.Enabled = true wait(0.001) script.Parent.Light4.PointLight.Enabled = false wait(0.001) script.Parent.Light5.PointLight.Enabled = true wait(0.001) script.Parent.Light5.PointLight.Enabled = false wait(0.001) script.Parent.Light6.PointLight.Enabled = true wait(0.001) script.Parent.Light6.PointLight.Enabled = false wait(0.001) script.Parent.Light7.PointLight.Enabled = true wait(0.001) script.Parent.Light7.PointLight.Enabled = false wait(0.001) script.Parent.Light8.PointLight.Enabled = true wait(0.001) script.Parent.Light8.PointLight.Enabled = false wait(0.001) script.Parent.Light9.PointLight.Enabled = true wait(0.001) script.Parent.Light9.PointLight.Enabled = false wait(0.001) script.Parent.Light10.PointLight.Enabled = true wait(0.001) script.Parent.Light10.PointLight.Enabled = false wait(2) end`
You can't used script.Disabled
to control a script, because once it's disabled, it cannot turn itself back on.
It's also a bad idea to use Disabled, because it adds unnecessary hidden state.
Just use a variable instead.
You should use a loop to go over the pointlights, instead of naming them individually.
while wait() do -- Use good variable names. "l" doesn't tell you anything -- "hour" is easier to read and write. local hour = game.Lighting:GetMinutesAfterMidnight()/60 -- AND, not OR (with or it would be always) local daytime = hour > 6 and hour < 18 if daytime then for i = 1, 10 do local light = script.Parent["Light" .. i].PointLight light.Enabled = true wait() light.Enabled = false end end end
EDIT: If you want the lights to blink on / off, first consider the two behaviors lights have: They either are 1) always off or 2) blinking. Let's simplify by first implementing as 1) always off and 2) always on:
In other words, the Enabled
of each pointlight is the same as whether or not it's currently night:
while wait() do local hour = game.Lighting:GetMinutesAfterMidnight()/60 local nighttime = hour <= 6 or hour >= 18 for i = 1, 10 do local light = script.Parent["Light" .. i].PointLight light.Enabled = nighttime end end
If we want them to blink as before, do pretty much what you had originally:
while wait() do local hour = game.Lighting:GetMinutesAfterMidnight()/60 local nighttime = hour <= 6 or hour >= 18 for i = 1, 10 do local light = script.Parent["Light" .. i].PointLight light.Enabled = nighttime -- only true in night wait() light.Enabled = false -- always false end end
Thus in day it will be
off, off, off, off, off, off, ...
and in night
ON, off, ON, off, ON, off, ...
Can't you use a loop to do this it looks like a lot of boolean values here.