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

How can I get X number of children?

Asked by 9 years ago

How can I get X number of children of a model using a for i,v in pairs loop? Sorry this is a request, but I can't get an answer anywhere else.

1 answer

Log in to vote
0
Answered by 9 years ago

you can just use a regular for loop, like this:

local Children = Model:GetChildren() --Replace Model with whatever you want to get the children of
local NumChildren = 4 --Replace 4 with the number of children you want to get

local ObjectTable = {} --This is the table where the objects will be held
for i = 1,NumChildren do
    table.insert(ObjectTable,Childen[i])
end

Note: The objects returned will not be random, and if the model is left unchanged, it will return the same objects all the time

Ad

Answer this question