How to select all these parts at once?

So I have this script where if you click a lever it will make electricity work (aka. the PointLight inside the Light parts will be enabled)

How do I add it in the (???) area of the script so that the PointLight that is found in every Light part of the Lights model becomes enabled?

Here is a picture of the model in workspace to better understand:
image

Here is the script:

local DestroyPart = game.Workspace.MetalDoor
local Light = game.Workspace.Lights:GetChildren()

script.Parent.ProximityPrompt.Triggered:Connect(function()
	DestroyPart:Destroy()
	???
end)

GetChildren() will get every direct child of Lights, but you want every child of every child all the way down. To do that we use GetDescendants(), and then check what type our objects are

local DestroyPart = game.Workspace.MetalDoor
local Light = game.Workspace.Lights

script.Parent.ProximityPrompt.Triggered:Connect(function()
	DestroyPart:Destroy()
	for _, child in Light:GetDescendants() do
		if child:IsA("PointLight") then
			child.Enabled = true
		end
	end
end)
2 Likes

Thank you so much for the thorough explanation!! I heavily appreciate it <3

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