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 1 year 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:

local onLight = script.Parent.StreetLightTimer.Lampstick.Lightpart.onLight

local offLight = script.Parent.StreetLightTimer.Lampstick.Lightingpart.offLight

while wait() do

if game.Lighting.ClockTime == 180000 then

    onLight.Enabled = true

    offLight.Enabled = true

        if game.Lighting.ClockTime == 6.65 then

        onLight.Enabled = false

        offLight.Enabled = false

        end

        end

end


2 answers

Log in to vote
2
Answered by 1 year ago

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

local onLight = script.Parent.StreetLightTimer.Lampstick.Lightpart.onLight
local offLight = script.Parent.StreetLightTimer.Lampstick.Lightingpart.offLight

local Lighting = game:GetService("Lighting")

local startOfDay = 6
local startOfNight = 18

local function checkIfDaytime(clockTime)
    if (clockTime >= startOfDay) and (clockTime < startOfNight) then -- if it's daytime
        return true
    elseif (clockTime >= startOfNight) or (clockTime < startOfDay) then -- if it's nighttime
        return false
    end
end

script:SetAttribute("Daytime", checkIfDaytime(Lighting.ClockTime)) -- creates the attribute
if script:GetAttribute("Daytime") == true then
    onLight.Enabled = false
    offLight.Enabled = false
else
    onLight.Enabled = true
    offLight.Enabled = true
end

script:GetAttributeChangedSignal("Daytime"):Connect(function()
    local attribute = script:GetAttribute("Daytime")
    if attribute == true then -- if it's true (day)
        onLight.Enabled = false
        offLight.Enabled = false
    else -- if it's false (night)
        onLight.Enabled = true
        offLight.Enabled = true
    end
end)

Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
    local clockTime = checkIfDaytime(Lighting.ClockTime)

    script:SetAttribute("Daytime", clockTime)
end)
0
Thank you so much I did not know loops don't work for this theking66hayday 841 — 1y
Ad
Log in to vote
1
Answered by 1 year ago
Edited 1 year 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:

local onLight = script.Parent.StreetLightTimer.Lampstick.Lightpart.onLight

local offLight = script.Parent.StreetLightTimer.Lampstick.Lightingpart.offLight

while wait() do

if game.Lighting.ClockTime == 18 then

    onLight.Enabled = true

    offLight.Enabled = true

        if game.Lighting.ClockTime >= 6.65 and game.Lighting.ClockTime <= 17.9 then

        onLight.Enabled = false

        offLight.Enabled = false

        end

        end

end

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 — 1y
0
i think its too exact, try using game.Lighting.ClockTime >= 6.65 and game.Lighting.ClockTime <= 17.9 then LikeableEmmec 470 — 1y
0
ok i will try that in a bit theking66hayday 841 — 1y
0
I tried using these signs < > each time I use them it gets underlined in red and also blue theking66hayday 841 — 1y
View all comments (2 more)
0
try the code i edited in the answer LikeableEmmec 470 — 1y
0
I tried it just now and it still the light won't turn off no errors theking66hayday 841 — 1y

Answer this question