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

How can I print each individual child?

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?

3 comments

3

Scripting Helpers is not a request site. Make an attempt first please.

0

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

0

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.

1 answer

Things to do

  1. Use in pairs
  2. 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



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.