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

Why won't my street lights turn on or off??

Asked by 2 years ago

I am trying to turn my street lights on and off when it hits a certain time. I want them to turn on at 180000 and off at 6.65 there are no errors. It just doesn't work at all.

Script:

01local onLight = script.Parent.StreetLightTimer.Lampstick.Lightpart.onLight
02 
03local offLight = script.Parent.StreetLightTimer.Lampstick.Lightingpart.offLight
04 
05while wait() do
06 
07if game.Lighting.ClockTime == 180000 then
08 
09    onLight.Enabled = true
10 
11    offLight.Enabled = true
12 
13        if game.Lighting.ClockTime == 6.65 then
14 
15        onLight.Enabled = false
View all 23 lines...

2 answers

Log in to vote
2
Answered by 2 years ago

Use my answer from an old question I solved. Don't worry I explained everything in that question.

01local onLight = script.Parent.StreetLightTimer.Lampstick.Lightpart.onLight
02local offLight = script.Parent.StreetLightTimer.Lampstick.Lightingpart.offLight
03 
04local Lighting = game:GetService("Lighting")
05 
06local startOfDay = 6
07local startOfNight = 18
08 
09local function checkIfDaytime(clockTime)
10    if (clockTime >= startOfDay) and (clockTime < startOfNight) then -- if it's daytime
11        return true
12    elseif (clockTime >= startOfNight) or (clockTime < startOfDay) then -- if it's nighttime
13        return false
14    end
15end
View all 41 lines...
0
Thank you so much I did not know loops don't work for this theking66hayday 841 — 2y
Ad
Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

I'm slightly confused, why make it happen at 180000? That cant happen in ClockTime. The most you can do is 18, and that works. Try this code:

01local onLight = script.Parent.StreetLightTimer.Lampstick.Lightpart.onLight
02 
03local offLight = script.Parent.StreetLightTimer.Lampstick.Lightingpart.offLight
04 
05while wait() do
06 
07if game.Lighting.ClockTime == 18 then
08 
09    onLight.Enabled = true
10 
11    offLight.Enabled = true
12 
13        if game.Lighting.ClockTime >= 6.65 and game.Lighting.ClockTime <= 17.9 then
14 
15        onLight.Enabled = false
View all 23 lines...

Hope this helps!

0
Yay it now turns on I think I must of thought that timeofday and clocktime was the same the only issue is that it still won't turn off theking66hayday 841 — 2y
0
i think its too exact, try using game.Lighting.ClockTime >= 6.65 and game.Lighting.ClockTime <= 17.9 then LikeableEmmec 470 — 2y
0
ok i will try that in a bit theking66hayday 841 — 2y
0
I tried using these signs < > each time I use them it gets underlined in red and also blue theking66hayday 841 — 2y
View all comments (2 more)
0
try the code i edited in the answer LikeableEmmec 470 — 2y
0
I tried it just now and it still the light won't turn off no errors theking66hayday 841 — 2y

Answer this question