Ok so I'm using :GetChildren and I want to print each individual child's name, and get the amount of children. How do I do this?
COMMUNITY QUESTION
How can I print each individual child?
1 answer
Things to do
- Use in pairs
- Use the # operator.
In Pairs
In pairs will return the interval and the value of the table. GetChildren is a table since it is a table of object values.
t = {1,2,"a","d",c = 12, q = 20}
for i,v in pairs(t) do
print(i,v)
end
Fun Facts about In Pairs
- In pairs was used in this wiki article: http://wiki.roblox.com/index.php?title=How_do_I_ban_people_from_my_place
The # operator
In the wiki we can see an operator, #x, which returns the length of a table.
t = {"a", "b", "c"}
local children = workspace.Model:GetChildren() --Inside the model there is 5 parts.
print(#t, #children) --prints 3-5 since there is 3 values in t and 5 parts in the model.
Fun Facts about The # Operator
- There is a metamethod associated with #, it is the __len metamethod.
Final Product
local c = workspace.Model:GetChildren()
for _,obj in pairs(c) do
print(obj)
end
print(#c)
Hope this helps!
4 comments
0
I think he's talking about 'Part Within Model Within another Model'. :P Meaning, all BaseParts that are in the game.
0
That about oversums it up :P
0
@TheAlphaStigma , I think that would be going a little too deep, he didn't even give a sample question, he should research more.
0
@LordDragonZord I am aware of that. :P I was just pointing out what he might have been referring to. :)
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Scripting Helpers is not a request site. Make an attempt first please.
Scripting Helpers is not a Request site; Please attempt to make your code first, we can not make scripts nor codes for you. However, this can be accomplished by using the 'For' loop; http://wiki.roblox.com/index.php?title=For_loop#For and 'Function's; http://wiki.roblox.com/index.php?title=Function
Well, he did say he was using "GetChildren". Although, showing us what you've worked on so far would help clarify what it is you're trying to do.