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

how do you count the children of an object ?

Asked by 6 years ago

i have no idea how to count the children of the player's backpack

i tried to do it with loops but that counted all of the items in the inventory when i just need the total number of items (i did it in a loop because when i pick something up i want it to recount the number of items)

local i = 1

while i < 10 do
    bpitems = BackPack:GetChildren()

    for i = 1, #bpitems do
        print(i, bpitems[i].Name)

        hmi.Value = i 
        print(hmi.Value  ..   'This is the value')
    end
    wait(0.2)
end

(when i did this it counted all the things one for one i just need it to say something like you have 5 total items NOT like "1","2","3","4","5" )

1
Can you not repost your questions or delete your queston just to post it again. User#5423 17 — 6y

2 answers

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

You can use the # operator on a table to get its length. In this case, use # on Backpack:GetChildren() to get the number of all direct children of the backpack.

print("You have", #BackPack:GetChildren(), "total items")
Ad
Log in to vote
0
Answered by 6 years ago

It is pretty simple, make a custom backpack cause the default one can' t be edited.

Answer this question