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

Two Part with two lights enabled true/false?

while true do
game.Lighting.TimeOfDay = ("12:00:00")
game.Workspace:GetChildren("PointLight").Enabled = false
wait(5)
game.Lighting.TimeOfDay = ("01:00:00")
game.Workspace:GetChildren("PointLight").Enabled = true
wait(5)
end

Any parts that have PointLight shall be enabled at 01:00:00 not 12:00:00.

1 answer

✓ Accepted answer

You could use a simple recursive loop.

function toggleLights(state)
	local lights={}
	local function recurse(p)
		for i,v in next, p:GetChildren() do
			if #v:GetChildren() > 0 then
				recurse(v)
			end
			if v:IsA("PointLight") then
				v.Enabled=state
			end
		end
	end
	recurse(workspace)
end

while true do
	game.Lighting.TimeOfDay = ("12:00:00")
	toggleLights(false)
	wait(5)
	game.Lighting.TimeOfDay = ("01:00:00")
	toggleLights(true)
	wait(5)
end

(Tell me if this doesn't work, I just quickly wrote this up)

1 comment

0

There's no need to check if it has at least 1 child--it works exactly the same for empty objects. That said, is there a good reason to use next instead of pairs?

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