Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I feel like I missing a variable, and why? Help me fix this problem please.

Asked by 9 years ago

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.

01while(wait())do
02local l = game.Lighting:GetMinutesAfterMidnight()/60 -- Get hours after midnight :3
03script.Disabled = l>6 or l<18 -- If it's before 6AM, or after 6PM turn it on
04end
05if script.disabled == true then
06    script.Parent.Light1.PointLight.Enabled = true
07    wait(0.001)
08    script.Parent.Light1.PointLight.Enabled = false
09    wait(0.001)
10    script.Parent.Light2.PointLight.Enabled = true
11    wait(0.001)
12    script.Parent.Light2.PointLight.Enabled = false
13    wait(0.001)
14    script.Parent.Light3.PointLight.Enabled = true
15    wait(0.001)
View all 46 lines...

2 answers

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

01while 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
15end

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:

1while 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
8end

If we want them to blink as before, do pretty much what you had originally:

01while 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
10end

Thus in day it will be

off, off, off, off, off, off, ...

and in night

ON, off, ON, off, ON, off, ...

0
The reason why I am turning on and off, is that it's considered runway lights. dluckey20 25 — 9y
0
Oh, that makes sense. I will edit my answer to reflect that. [Done] BlueTaslem 18071 — 9y
0
Thank you very much. It works great stop by once and I'll show you. dluckey20 25 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Can't you use a loop to do this it looks like a lot of boolean values here.

Answer this question