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”
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
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
op asked for children not descendants, also to format code just press this button then paste your code in it:
not working
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)
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
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.
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??
Nevermind it’s now working. Thanks!
No problem, but don’t mark my post as the solution mark either @JustNylo or @Femtrs as the solution.
Done
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.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.