Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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()

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. alphawolvess 1784 — 5y
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 DanzLua 2879 — 5y
Ad

Answer this question