Streetlight wont work

Hello. I was trying to make a working streetlight. Upon scripting, I failed (like always lol)
Script:

local lighting = game.Lighting
local lightpart = script.Parent.light

lightpart.SpotLight.Enabled = false

if lighting.ClockTime == 17.2-7 then
	lightpart.SpotLight.Enabled = true
elseif lighting.ClockTime == 7-17.2 then
	lightpart.SpotLight.Enabled = false
end

btw streetlight activates during night and is inactive during day

Try using <,>, >= or <=

This is what it would look like:


if lighting.ClockTime >= 17.2 and lighting.ClockTime <= 7 then
   --Night
else
   --Day
end

Since “==” means “Is equal to” it will only happen (If time moves) IF it is that time.

Not the entire night cycle

It does not work still.

abcdef

you’re going to need a loop or Change detector

Put it in a while loop

while wait() do
   --Code
end

Or do that

This is better than a while loop

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	--Code
end)

better to do property change signal:

lighting:GetPropertyChangedSignal('ClockTime'):Connect(function(clockTime)

end)
local lighting = game:GetService("Lighting")
local lightpart = script.Parent.light

lighting:GetPropertyChangedSignal('ClockTime'):Connect(function()

	lightpart.SpotLight.Enabled = false

	if lighting.ClockTime >= 17.2 or lighting.ClockTime < 7 then
		lightpart.SpotLight.Enabled = true
	else
		lightpart.SpotLight.Enabled = false
	end

end)

It works in run test but doesn’t work in play test???
EDIT: ok nvm it doesnt work when i change the lighting settings manually in playtest, gotta do it with admin cmds

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.