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.
01 | while (wait()) do |
02 | local l = game.Lighting:GetMinutesAfterMidnight()/ 60 -- Get hours after midnight :3 |
03 | script.Disabled = l> 6 or l< 18 -- If it's before 6AM, or after 6PM turn it on |
04 | end |
05 | if script.disabled = = true then |
06 | script.Parent.Light 1. PointLight.Enabled = true |
07 | wait( 0.001 ) |
08 | script.Parent.Light 1. PointLight.Enabled = false |
09 | wait( 0.001 ) |
10 | script.Parent.Light 2. PointLight.Enabled = true |
11 | wait( 0.001 ) |
12 | script.Parent.Light 2. PointLight.Enabled = false |
13 | wait( 0.001 ) |
14 | script.Parent.Light 3. PointLight.Enabled = true |
15 | wait( 0.001 ) |
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.
01 | while wait() do |
02 | -- Use good variable names. "l" doesn't tell you anything |
03 | -- "hour" is easier to read and write. |
04 | local hour = game.Lighting:GetMinutesAfterMidnight()/ 60 |
05 | -- AND, not OR (with or it would be always) |
06 | local daytime = hour > 6 and hour < 18 |
07 | if daytime then |
08 | for i = 1 , 10 do |
09 | local light = script.Parent [ "Light" .. i ] .PointLight |
10 | light.Enabled = true |
11 | wait() |
12 | light.Enabled = false |
13 | end |
14 | end |
15 | 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:
1 | while wait() do |
2 | local hour = game.Lighting:GetMinutesAfterMidnight()/ 60 |
3 | local nighttime = hour < = 6 or hour > = 18 |
4 | for i = 1 , 10 do |
5 | local light = script.Parent [ "Light" .. i ] .PointLight |
6 | light.Enabled = nighttime |
7 | end |
8 | end |
If we want them to blink as before, do pretty much what you had originally:
01 | while wait() do |
02 | local hour = game.Lighting:GetMinutesAfterMidnight()/ 60 |
03 | local nighttime = hour < = 6 or hour > = 18 |
04 | for i = 1 , 10 do |
05 | local light = script.Parent [ "Light" .. i ] .PointLight |
06 | light.Enabled = nighttime -- only true in night |
07 | wait() |
08 | light.Enabled = false -- always false |
09 | end |
10 | 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.