✓ Accepted answer
#What you can do
I know this was answered twice already and this is also 19 hours old but there is a MUCH more simpler way to get the number of items inside of a table.
#Operators
There are many types of operators that are distributed into 4 categories:
- Logical
- Relational
- Arithmetic
- Miscellaneous
We're trying to find something that would return the length of something, so it wouldn't be Arithmetic or Logical and it can't be Relational either, so we'll look in Miscellaneous. The 2nd item on the list the ROBLOX Wiki gives us is the operator with the pound sign(#), the name of the operator/operation is "Length of Table"(Even though it'll work with the length of a string as well), this is perfect!
####Example of using "Length of Table"
local table = {1, nil, {"Red","String"}, true, workspace.BasePlate, BrickColor.new(1), CFrame.new()}
print(#table)
7
It prints "7" because there are 7 things inside of the table. This is perfect for your inventory script.
#Final Product
I know the explanation was long, but your modified script will be short, very short.
inventory={"Sword","Arrow"}
print(#inventory)
2
#Hope it helps!
##Extras
Here's a quick function I made that will print the amount of things inside of any table:
function readtable(x)
if type(x) == "function" then
return #x
end
end
readtable([Insert Table here])