Changing the model's children

Is there a way to access all the children under a model/folder?

For example I want to change the transparency of all the parts under a model.
Is there a way to not list them 1 by 1?

I don’t want this:

local Model = script.Parent

function Click()
Model.ExamplePart1.Transparency = 0
Model.ExamplePart2.Transparency = 0
Model.ExamplePart3.Transparency = 0
Model.ExamplePart4.Transparency = 0
Model.ExamplePart5.Transparency = 0
end

I want this:

local Model = script.Parent
local Children = Model.Children

function Click()
Children.Transparency = 1
end

(i know you can’t actually do this but its just an example)

Any help is appreciated!

local Model = -- Model Here

local function ChangeTransparency()
   for _, Part in Model:GetChildren() do
      if not Part:IsA("BasePart") then
          continue
      end

      Part.Transparency = 1
   end 
end

ChangeTransparency()
2 Likes

Thank you so much, makes my script a lot more clear!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.