Title may seem odd but I'm after a script which when run it does something on this lines of this: Model>Model>Model>Parts So it basically searches the models of models to find a property of the parts. So the current script I have goes to an exact location and gets the children then changes the brick color. Is there any possible way of doing what I mentioned before about finding the properties of parts within multiple models.
for a = 1, 11 do colour = "Really black" local children = Workspace.Vehicles.Jeep.VehicleBody.Color:GetChildren() for i = 1, #children do children[i].BrickColor = BrickColor.new(colour) end end
Thanks.
You'll need to use recursion, which is the act of a function calling itself to loop through nested items. The function loops through the highest level of the model, and if it finds any children that are parts, it makes them black. If it's a model, it calls the function with that child, looping through all of those and repeating the same process.
function makeBlack(model) for _,child in ipairs(model:GetChildren()) do if child:IsA('Part') then child.BrickColor = BrickColor.new('Really black') elseif child:IsA('Model') then makeBlack(child) end end end makeBlack(Workspace.Vehicles.Jeep.VehicleBody.Color)
This is very untested, and recursion can sometimes make the game crash if not done right.