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
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)
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!