Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can you use :GetDescendants() to select the children of a model?

So in my script I want to get the children (or children's children) of a model which you put on separately which can have a random number of parts, and when you press a button those parts' transparency will become 1. The closest kind of technique to getting the children of an object is :GetDescendants, I use that over GetChildren because its easier to script in. I want to put the :GetDescendants into a function but the only way which the Wiki tells you to do it is by making a script like this.

for index, descendant in pairs(descendants1) do
	descendants1.transparency = 1
	end
for index, descendant in pairs(descendants2) do
	descendants2.transparency = 1
	end
for index, descendant in pairs(descendants3) do
		descendants3.transparency = 1
		
end

In summary, I want to put that in a function and make all the children of a model become invisible by using a script.

1 answer

✓ Accepted answer

OK so I'm doing something similar but here is what id recommend trying.

for i,v in pairs(script.parent) do
    if v:IsA("Part") then
        v.Transparency = 0
    else
        print'not needed'
    end
end

it is saying that if v is a part it will make it transparent. If it isn't it will print 'not needed'. Make sure to accept answer if this helps. Good luck!

4 comments

0

you forgot to use :GetDescendants()

0

replace script.parent with your reference like game.Workspace.Model:GetDcendents()

0

I'll try it real quick, do I change "v" to anything?

0

v is just the variable, if you want to change the name, to say "thingy" change the place where it defines it in this case the pairs loop: for i,thing in pairs

This discussion is preserved as it was. New answers, comments, and votes are closed.