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

GetChildren method help?

This is part of a script I'm making, it it SUPPOSED to turn lights off when the power goes off. Here is the script:

local p = game.Workspace.Lighting:GetChildren()
		for i = 1,#p do
			p.PointLight.Enabled = false
		end	

However, this doesn't work. Help?

1 answer

First, make sure that every instance in workspace.Lighting contains a PointLight. If your script encounters one that does not, it will fail. Also, you may want it to be a recursive function in case the light isn't located directly inside the object in Lighting.

This code will loop through every instance in workspace.Lighting and turn off any PointLights:

function LightsOff(Instance)
	for i,v in pairs(Instance:GetChildren()) do
		if v:IsA("PointLight") then v.Enabled=false end
		LightsOff(v)
	end
end

LightsOff(workspace.Lighting)

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