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:
01 | local onLight = script.Parent.StreetLightTimer.Lampstick.Lightpart.onLight |
02 |
03 | local offLight = script.Parent.StreetLightTimer.Lampstick.Lightingpart.offLight |
04 |
05 | while wait() do |
06 |
07 | if 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 |
Use my answer from an old question I solved. Don't worry I explained everything in that question.
01 | local onLight = script.Parent.StreetLightTimer.Lampstick.Lightpart.onLight |
02 | local offLight = script.Parent.StreetLightTimer.Lampstick.Lightingpart.offLight |
03 |
04 | local Lighting = game:GetService( "Lighting" ) |
05 |
06 | local startOfDay = 6 |
07 | local startOfNight = 18 |
08 |
09 | local 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 |
15 | end |
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:
01 | local onLight = script.Parent.StreetLightTimer.Lampstick.Lightpart.onLight |
02 |
03 | local offLight = script.Parent.StreetLightTimer.Lampstick.Lightingpart.offLight |
04 |
05 | while wait() do |
06 |
07 | if 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 |
Hope this helps!