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

How do I use GetChildren() properly?

Asked by 7 years ago

Yes, I'm a noob to all this, and that is why ScriptingHelpers is a thing. Thank you for those guys who take the time to read this question, and attempt to answer it. I appreciate it a lot.

There is a modelA, and inside modelA, there is modelB. The Script is in another model.

What I'm trying to do, is figure out how can I get the bricks of modelB and set their transparency to 1.

Thanks!

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Okay, here's a step by step:

First, define Model B.

ModelB = game.WorkspaceModelA.ModelB -- Or similar, I don't know how your structure goes

Now you need to use :GetChildren() to get every child of ModelB, arranged in a table.

Children = ModelB:GetChildren()

Now you have the table. From here, we use a loop. I'm going to use the for loop, as it is the most appropriate.

ModelB = game.Workspace.ModelA.ModelB
Children = ModelB:GetChildren()

for i,v in ipairs(Children) do -- For reference, i,v means index, value.
    v.Transparency = 1 -- This loop will not lag out the entire server as it has an end point, when everything is done. Also, we operate on v because the item is v, i is the number assigned to it in the table for code reference.
end

You're welcome. Tell me if you have any more problems.

Ad

Answer this question