How to make all children invisible

Hello,

How would you select all the children of a part and make them invisible? Not including the parents children, children.

for i, v in pairs(Part:GetChildren()) do
     v.Transparency = 1
end

You may want to add a check if it is a BasePart in case.

If you have decals and such, you may tweak it accordingly.

for _,v in part:GetChildren() do
	if not v:IsA('BasePart') then continue end
	
	v.Transparency = 1
end

1 Like
for _, v in pairs ((part name):GetChildren()) do
if v:IsA("Part") then
v.Transparency = 1
end

What do you mean by this statement? I’m confused

If you want all the children of a certain part to become invisible, then all the codes above should work. But if you’re talking about in studio, then that is not possible currently.

Here is some full code if this is more helpful or self-explanatory:

local Part = script.Parent --this is the part where all its children will become invisible

Part.Changed:Connect(function() --I only put .Changed because I don't know what you mean by select. If you've already set up some kind of selection module or something, then change it to module.NAMEOFFUNCTIONHERE
    for I,v in pairs(Part:GetChildren()) do
        if v:IsA("Part") then --add any other :IsA statements if you want some other things to become transparent too
            v.Transparency = 0
        end
    end
end)

Hope this is helpful :slight_smile:

They probably went offline and didn’t mark any of the comments as a solution. Don’t worry. I think all of our codes are right. Also i think they meant only the children, not the parents.

for i, child in pairs(part:GetChildren()) do
	if child:IsA("BasePart") then
		child.Transparency = 1
	end
end

This will check if each child is a part before making it invisible so it doesn’t error if you have any children that aren’t parts.

My script does make the children invisible

Bro they didn’t check any of these as solved :skull::skull::skull::skull:

It would be better to check if the child directly has a transparency property for future proofing

for _, obj in ipairs(Part:GetChildren())
   if not obj.Transparency and typeof(obj.Transparency) ~= "Instance" then continue end

   obj.Transparency = 1
do