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

How do i count the amount of items in a players backpack?

I want to know how to count the amount of tools in a players backpack so I can associate it with a different script.

1 answer

✓ Accepted answer

To get the number of items within the backpack, you can just do the below:

local NumberOfContents = #Player.Backpack:GetChildren()

GetChildren() returns a table containing all of the children in the instance you have called it upon. With tables, you can obtain the number of contents by using #.

There are exceptions but you should not run into these exceptions if the table is from :GetChildren()

2 comments

0

Take note that I use Player as a place holder for the player instance, I am unsure how you want the Player to be obtained.

0

Just keep in mind that if a player has a tool equipped the script won't count that, you can account for that by adding +(Player.Character:FindFirstChildOfClass("Tool") and 1 or 0) to the end

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