Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Colouring Multiple Parts At Once?

Asked by 4 years ago
Edited 4 years ago

Hello! I have a bunch models called 'Tree', I want to change the colour of each child In every model called Tree (named 'Part'.)

So: Workspace.Tree.Part

My problem is when the script only changes 'Part' from one of the models, not all of them.

through a script without having to write a code for every single one of them would do the job but would take forever to Script (Especially since I'm bad at coding in general.) Is there a more efficient way to change the colour each part from the model?

My Seriously bad and simple code:

game.Workspace.Tree.Part.BrickColor = BrickColor.new("Mauve")

Thank you. :)

1 answer

Log in to vote
1
Answered by
Elyzzia 1294 Moderation Voter
4 years ago
Edited 4 years ago

first, you need to group all of the trees into a model or a folder

you can do that by selecting them all and just pressing ctrl + g

now that they're all grouped, you can easily get every single tree in a nice list like this

local treesList = workspace.Trees:GetChildren()

and now that they're in a list (which is usually called a table), you can use a pairs loop to go through every single tree in the list and run the same code for every single one

local treesList = workspace.Trees:GetChildren()

for _, tree in pairs(treesList) do -- the first value is an underscore because it's not useful in this scenario. usually it's called the table index
    tree.Part.BrickColor = BrickColor.new("Muave")
end
Ad

Answer this question