hi. i'm a beginner scripter and i need help.
building a streetlight automatic system thing. turn off day and turn on night. can someone help me fix it? it isn't working?
if game.Lighting.ClockTime == "6" then script.Parent.Enabled = false elseif game.Lighting.ClockTime == "18" then script.Parent.Enabled = true end
any help would be helpful. tysm y'all
So, for starters, write more "clean" script.
Anyway, as some people pointed out in the comments, the script
does not loop. Next is the fact that we have to assume that the script
is in the light
. If it is not, this explains why (you used script.Parent.Enabled = true
). If it is, I would move it into the part
the light
is parented by.
The script I would try would be something along the lines of...
local Light = script.Parent.Light --[[light's name here, for now I'll just use "Light"--]] local Lighting = game.Lighting Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function() local time = Lighting.ClockTime if time == 6 then Light.Enabled = false elseif time == 18 then Light.Enabled = true end end)
Also: Just noticed this, but you don't need quotes with numbers. You only need quotes for anything (starting) with non-number characters (with exceptions for certin things like true
) like "world856"
and "what in the world"
compared with 84FallingTree
or 7
while true do wait() if game.Lighting.ClockTime == "6" then script.Parent.Enabled = false elseif game.Lighting.ClockTime == "18" then script.Parent.Enabled = true end end