How can I make a script that changes the color of all the contents (parts only) inside a model to a certain ID. I have no idea what I am doing lol.
local model = workspace.FerrisWheelLights2 local color = Color3.fromRGB (0, 255, 0) local child = model:GetChildren() child.Color = color
I am clearly not the best scripter but yeh.
Do this
local model = workspace.FerrisWheelLights2 local color = Color3.fromRGB (0, 255, 0) local child = model:GetChildren() for i,v in ipairs(child) do v.Color = BrickColor.new(Color3.fromRGB(40,255,255)) end
You are able to iterate through all of the descendants of the model (which includes every object inside it), and change the colour of each object inside. You must check if each object is a BasePart (which includes Parts, Wedges, Unions, etc.) before changing the colour, otherwise it will error when it comes across an object that doesn't have a Color property. In this example, the for
loop will allow you to iterate through the model's descendants, and each iteration the object can be referred to as the variable Part
(defined in the loop).
local model = workspace.FerrisWheelLights2 local color = Color3.fromRGB (0, 255, 0) local descendants = model:GetDescendants() for _,Part in pairs(descendants) do if Part:IsA("BasePart") then Part.Color = color end end
Basically, GetDescendants()
returns a table of every object inside the model, including children of children and so on, while GetChildren()
only gives you the direct children of the model (and not the children of those children).
Hope this helps!
So basically there's a pairs
loop you can use with :GetChildren()
to get all the stuff in a model
local model = workspace.FerrisWheelLights2 local color = Color3.new(0, 255, 0) for i,v in pairs(model:GetChildren()) do if v:IsA("BasePart") then v.Color3 = color end end