Hi, I am trying to make streetlights turn on at certain times, but my script isn't working. No errors, no nothing. Please help :D

local lights = script.Parent:GetChildren()

game.Lighting:GetPropertyChangedSignal("TimeOfDay"):Connect(function()
	for i, child in ipairs(lights) do
		if child.Name == "SurfaceLight" then
			if game.Lighting.TimeOfDay == "17:00:00" then
				child.Enabled = true
			elseif game.Lighting.TimeOfDay == "08:00:00" then
				child.Enabled = false
			end
		end
	end
	wait()
end)

2 comments

1

Try to use pairs instead of ipairs - if it still does the same put a print after the (for i, child in pairs) statement to debug if it's finding any lights, also I wouldn't recommend having the (for loop) done every single time TimeOfDay is changed if it's a constant night cycle system because otherwise you're gonna cause a lot of stress on the server.

0

Cool, I'll try pairs instead of ipairs and the print debug.