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

Can anyone teach me how to print lists from a player's backpack?

Asked by
thePyxi 179
7 years ago

I question popped in my head.

"How can I list all the items in a player's backpack?"

I tried to make it work but it utterly failed...

So, I was wondering if anyone would be willing to teach me all the things that would be included in lists.

2 answers

Log in to vote
0
Answered by 7 years ago

The best way,

Volodymyr2004 suggested using a for loop. Don't. Use a pairs loop. Pairs loops are made specifically for this purpose.

local backpack = player.Backpack
local children = backpack:GetChildren()

for i,v in pairs(children) do
    print(v.Name)
end
Inside the loop v will equal the current item the loop is looping through, if that makes sense.

Good Luck!

If I did help, please don't forget to accept my answer.
Ad
Log in to vote
0
Answered by 7 years ago

You can get the children of backpack,

local tools=BackPack:GetChildren()

Then you can list of the items 1 by 1 in a loop until all items have been listed

for i=1, #tools do --will go through children 1 by 1
    print(tools[i].Name) --prints tool's name
end --end

Hope this helped!

Answer this question