Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
-1
Answered by 4 years ago

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!

0
you forgot to use :GetDescendants() Leamir 3138 — 4y
0
replace script.parent with your reference like game.Workspace.Model:GetDcendents() DAKNCAMGAMING 45 — 4y
0
I'll try it real quick, do I change "v" to anything? Pyro_dood 31 — 4y
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 emervise 123 — 4y
Ad

Answer this question