Making a script reference all of the parts within a model

How would I change this script so that it changes all of the parts named “Part” within a given model without having to change their names to reference them all individually?

local model = game.Workspace.ModelTest

model.Part.Transparency = 0.5

model.Part.Color = Color3:fromRGB(113,113,113)

What I don’t want to have to do (if possible):

local model = game.Workspace.ModelTest

model.Part1.Transparency = 0.5
model.Part1.Color = Color3:fromRGB(113,113,113)
model.Part2.Transparency = 0.5
model.Part2.Color = Color3:fromRGB(113,113,113)
model.Part3.Transparency = 0.5
model.Part3.Color = Color3:fromRGB(113,113,113)
model.Part4.Transparency = 0.5
model.Part4.Color = Color3:fromRGB(113,113,113)
-- and so on...

For i,v in ipairs should be perfect for you!

It actually works like this

For every i(ndex),v(alue) in(side) ipairs ([ModelName]:GetChildren()) do

EDIT, my internet had a stroke and i lost the full comment.

So, inside the for loop you can check every value inside your model like this

If v.Name(checks for all the parts) == “Part” then
V.transparency = 0.5
–more
End

Output
Every part will be half transparent
You can use the same for changing the colors

1 Like
local model = game.Workspace.ModelTest

for i, child in ipairs(model:GetChildren()) do
	if child.Name == "part" then
            child.Transparency = 0.5
            child.Color = Color3:fromRGB(113,113,113)
        end
end)

3 Likes

Thanks for the help :smiley: