Hello I wanted to ask how to get the number of items in the Inventory of the Player.
You can simply do
#Player.Backpack:GetChildren()
This would return a number value of how many instances are in the backpack.
You have the get the Players Backpack and use a for loop to get all the items.
I will try it out i hope this works
local Player = game.Players.LocalPlayer
local BackPack = Player:WaitForChild("BackPack")
while wait(1) do
script.Parent.Text = tostring(BackPack:GetChildren())
end
This is my script doesn’t works why?
The Backpack’s name is not BackPack, you spelled it wrong on line 2.
you should correct it to Backpack
I did it and it shows an table what to do now?
I think it shows a table because GetChildren gets Instances!
Also on line 4 it should be:
script.Parent.Text = tostring(#BackPack:GetChildren())
what does the hashtag do can u explain it?
It returned the number of instances in the child
ah it worked Thank you and also for explaining
it gets the length of a table
lets say, for example
print(#{1,2,3,4})
that would print 4
Ah ok didn’t now that thanks
I found a little error every time i unequip an item it it shows the right number of items but if i equip an item it shows the right number but -1 so if i have 2 items it shows only 1!
When you equip a tool, the tool parents in the character.
I think you should try to loop on all the Children (Items, Tools, etc…) inside the backpack and get the value of How many Items are there. Hope this helps. Try to learn loop methods.
I hope this helps. Thank you.
Thanks, but i already now for loops i just forgot to use them for this script.
Well, That’s nice. but Unfortunately, I can’t help you beyond this point, I hope you’ll find the proper solution for that Soon! Thank you.
I used a for loop and it didn’t work for me only with while so it must be an other problem.