How can I make It where It selects all the parents with the same name work with a button

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? makes a part change color with same name with a press of a button

  2. What solutions have you tried so far? I tried looking for solutions & help on devforum & couldn’t find any solution.

It’s the very last line I am trying to get to work:
“game.Workspace.GorillaCubeLights.Round_Cube.BrickColor = BrickColor.new(9, 137, 207) --LED”

I have 300 of the same parts that have the same name I am trying to all get to change color when pressing a button

function Check()
if script.Parent.Power.Value == true then
game.Workspace.GorillaLights.BrickColor = BrickColor.new(1, 1, 0) --LED
game.Workspace.GorillaLights2.BrickColor = BrickColor.new(1, 1, 0) --LED 2
game.Workspace.GorillaLights.SurfaceLight.Color = Color3.new(1, 1, 0) --Light
game.Workspace.GorillaCubeLights.Round_Cube.BrickColor = BrickColor.new(9, 137, 207) --LED
wait(0.1)
end
end

while true do
Check()
wait()
end
function Check()
	if script.Parent.Power.Value == true then
		game.Workspace.GorillaLights.BrickColor = BrickColor.new(1, 1, 0) --LED
		game.Workspace.GorillaLights2.BrickColor = BrickColor.new(1, 1, 0) --LED 2
		game.Workspace.GorillaLights.SurfaceLight.Color = Color3.new(1, 1, 0) --Light
		for i, child in game.Workspace:GetChildren() do
			if child.Name == "GorillaCubeLights" then
				child.Round_Cube.BrickColor = BrickColor.new(9, 137, 207) --LED
			end
		end
	end
end

while true do
	Check()
	wait()
end

also, you are going to have some trouble. BrickColor.new() need a color NAME, not RGB code. just like that:

BrickColor.New("Really Red")

If you want further help, could you be more specific on what part you need to update ?
If you could send a screen of your explorer that would help


I see your polling here, when usually this should be avoided, how does the button work, is it a TextButton? ClickDetector?

Other than that, if you want to check for every part with a certain name, assuming they are all distributed throughout the workspace, you can use :GetDescendants() to retrieve every part within a certain folder or the workspace and check if it’s name is something.

image

I need where It collects all the parts with the same name & changes the color.

function Check()
	if script.Parent.Power.Value == true then
		for i, child in game.Workspace.GorillaCubeLights:GetChildren() do
			if child.Name == "Round_Cube" then
				child.BrickColor = BrickColor.new(9, 137, 207) 
			end
		end
	end
end

while true do
	Check()
	task.wait() -- try to use task.wait() and not just wait()
end

ohhh ok I see, thank you so much for your help!

Make sure to mark “Solved” when you are done, so other people know what the solution is.
And your welcome !

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