Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 comments

0

it only runs once

0

maybe wrap it in a GetPropertyChangedSignal event

2 answers

✓ Accepted answer

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

8 comments

0

WITW tysm for helping, now i understand ee

0

doesn't work.

0

dude doesnt work

0

he probably meant Lighting:GetPropertyChangedSignal("ClockTime")

0

I also typed this in ScriptingHelpers, so I might have some errors. Typo-proof as needed.

0

--- I attempted to fix some of my simple errors (I haven't scripted in months) ---

0

worked, thanks!

0

np

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

3 comments

0

causes too much lag

0

tried this lmao

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.