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

Streetlight Script not working at all, no errors. ??

Asked by 5 years ago

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

0
it only runs once theking48989987 2147 — 5y
0
maybe wrap it in a GetPropertyChangedSignal event theking48989987 2147 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

0
WITW tysm for helping, now i understand ee BuzzKillGT 33 — 5y
0
doesn't work. BuzzKillGT 33 — 5y
0
dude doesnt work BuzzKillGT 33 — 5y
0
he probably meant Lighting:GetPropertyChangedSignal("ClockTime") GoldAngelInDisguise 297 — 5y
View all comments (4 more)
0
I also typed this in ScriptingHelpers, so I might have some errors. Typo-proof as needed. GamingZacharyC 152 — 5y
0
--- I attempted to fix some of my simple errors (I haven't scripted in months) --- GamingZacharyC 152 — 5y
0
worked, thanks! BuzzKillGT 33 — 5y
0
np GamingZacharyC 152 — 5y
Ad
Log in to vote
-4
Answered by 5 years ago
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
0
causes too much lag GamingZacharyC 152 — 5y
0
tried this lmao BuzzKillGT 33 — 5y
0
you dont need the quotation marks, it is a value not a string. also, try putting the wait after the if statement to reduce the lag. Neon_isHere 100 — 5y

Answer this question