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

Listing number of children of an object?

I would like to list the number of children in an object.

For instance, I have a function where I get the users name and backpack and would like to list the number of items in their backpack, how would I do so?

1 answer

Not sure about the wording of the question.

If you want to get the number of children in an object, you can use the # operator, which will give you the length of the table that GetChildren() returns (which will be the number of objects inside the thing). For example:

local items = backpack:GetChildren()
print(#items)

Otherwise, if you want to print every item in a sort of 'list', you can iterate through the table of children and print each one:

for _,item in pairs(items) do
	print(item)
end

Hope this is what you were looking for.

4 comments

0

I want to do the first one however that does not seem to work, may I contact you on Discord?

0

Sure. My tag is mattscy#8289

0

Mrlongfoot#2400

0

you can also get it from a string. irrelevant to the answer and question but it's good to know for string manipulation in the future. upvote

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