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

How do I use GetChildren() properly?

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

✓ Accepted answer

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.

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