I've designed a model of a mouse. The mouse has a lot of parts to provide a wide window of customization for the player.
Screenshot of the Finished Model
Screenshot of model contents (put total part count beside folder name just to show viewers, it is not there normally)
I'm wanting to create a script that allows me to change the BrickColor property of all the parts that create the "body" , "secondary" , "skin" and "eye" color.
Most of the parts are union parts if that changes anything.
My longterm goal is to create a script that allows character customization at the start of game. With a variety of different colors that can be chosen from for each area of the creatures body. However, I know that is probably a bit more advanced so ill settle with simply learning how to change the folder contents to the same BrickColor property.
from looking around on the internet i've started with this:
local children = workspace.FieldMouse.body:GetChildren()
I can't seem to get much else to work though, I tried an if then statement to detect for a part and then change the property, but it didn't work...and I can't get much further than that.
I'm hoping someone can guide me in the right direction!
We can use a numeric for loop to iterate through the array returned by Instance:GetChildren()
like so:
local Children = game.Workspace:GetChildren() for Index = 1, #Children do local Child = Children[Index] -- Here we can do something for every child, but first we need to check if it's a part. if Child:IsA("BasePart") then Child.Color = Color3.new(0, 0, 0) end end
BasePart
is called the superclass all the possible types of parts, sort of like how objects in the game have parents and children, BasePart
is the parent of unions, mesh parts, wedge parts, normal parts, and so on.
We simply iterate through an array with a numeric for loop, starting at 1, and going up to the length of the array. For each iteration, we get the child in the table by looking up the numeric key in the array (Table[Key] gets the value at Key in Table).
If you'd like to know more about numeric for loops, check out the Roblox Wiki entry for them.