How would I get everything from a folder to change...?

I’m currently making a prison and I’m currently stuck since I am wanting to make a Lockdown system for the lights and will turn red when a ClickDetector is pressed. I have the button stuff down but since my Lights are in a folder. (Organization) I don’t know how to make it so those are all able to change color…

local LockdownButton = script.Parent
local clickDetector = LockdownButton.ClickDetector

function onMouseClick()

end
clickDetector.MouseClick:connect(onMouseClick)
local LockdownButton = script.Parent
local clickDetector = LockdownButton.ClickDetector
local lights= ... -- reference to Lights folder


function onMouseClick()
	--- sure lights folder only have light
	for k, light in pairs(lights:getChildren()) do
		wait()
		light.Color= Color3.fromRGB(255,0,0)
	end
end
clickDetector.MouseClick:connect(onMouseClick)

GetChildren() will return a table contain all children in it

1 Like

Hmmm… if I have a SpotLight and SurfaceLight how would I make it so both change color as well instead of only the SpotLight?

The one on the right is the SpotLight and the left is the Surface Light, The surface light won’t change colors.

image

local LockdownButton = script.Parent
local clickDetector = LockdownButton.ClickDetector
local lights = game.Workspace.Lights.Part
function onMouseClick()
	
	for k, light in pairs(lights:getChildren()) do
		wait()
		light.Color= Color3.fromRGB(255,0,0)
	end
end
clickDetector.MouseClick:connect(onMouseClick)

And if I do

game.Workspace.Lights

It doesn’t get the children of the parts (The Lights), instead it just gets the parts.

GetChildren only gets the direct descendants of the Folder.

Would I be able to do something like

local parts = lights.part 

then get the children for “parts”?

Name all the lights ‘Light’ and use that code.

3 Likes

Thank you, I was actually thinking of just renaming all the Light Sources and you somewhat did that for me!

1 Like