How to implement the following system:

How to loop through all the workspace children, and if there’s a part called “Part” , and its BrickColor is (“Deep orange”), then its name becomes “OrangePart”

4 Likes
for i, part in workspace:GetDescendants() do
 if part.Name:IsA("Part") and part.BrickColor == BrickColor.new("Deep orange") then -- checks if the part name is "Part" and part BrickColor is Deep orange
part.Name = "OrangePart" -- sets the part color
end
end

i learned how to make it look like a script lets go

2 Likes
for i, v in pairs(game.Workspace:GetChildren()) do
  if v.Name == "Part" and v.BrickColor == BrickColor.new("Deep orange") then
      v.Name = "OrangePart"
  end
end
4 Likes

op asked for children not descendants, also to format code just press this button then paste your code in it:
image

3 Likes

not working

1 Like

Any errors in console? Also is the Part called exactly "Part’? Lastly, is it a child of workspace or is it a child of a child (descendant)

2 Likes

I did this and did not receive any errors, hope this helps!

local workspace = game:GetService("Workspace")

-- Searches through the workspace and finds a Part that's named Part and the BrickColor is "Deep orange" then rename the Part to "OrangePart"
for index, value in pairs(workspace:GetChildren()) do
	if value:IsA("Part") and value.Name == "Part" and value.BrickColor == BrickColor.new("Deep orange") then
		value.Name = "OrangePart"
	end
end
2 Likes

It’s not working for me. I pasted it in the command bar. Is that the reason it’s not working?

That should work in command bar. Make sure you remove the comment before running it.

1 Like

Probably that’s the reason, since there is a comment and you pasted it in the console (one line), it’s blocking most of the other code from running.

Also, that’s the exact same code as @JustNylo wrote. You sure the color of your part is Deep orange??

1 Like

Nevermind it’s now working. Thanks!

1 Like

No problem, but don’t mark my post as the solution :sweat_smile: mark either @JustNylo or @Femtrs as the solution.

1 Like

Done

1 Like

May I ask why did you need this. Also incorrect use of channel, You arent supposed to ask for systems. But for help on making them.

1 Like

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