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?
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?
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
4 comments
I want to do the first one however that does not seem to work, may I contact you on Discord?
Sure. My tag is mattscy#8289
Mrlongfoot#2400
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