Heya folks, as you can tell by the title an inventory system with a module I made isn’t working. I tested it and changed a ton of things but for some reason, the inventory table is always empty and it’s filled up only within the module? Not sure what’s happening here, i’ve checked the other posts but none of them solved my problem. Help is appreciated.
inventory = {
}
invfunction = {}
function invfunction:Getsize()
return #inventory
end
function invfunction:AddItem(plr,object,counter)
if not plr then
warn("Not a player, returning")
return
end
if not inventory[plr] then
print("Created inventory, inventory didn't exist")
inventory[plr] = {}
end
for i,v in pairs(inventory[plr]) do
if v.item == object then
v.count = v.count + counter
print("Added "..counter.." Count to "..object)
print(inventory[plr])
print(#inventory)
return
end
end
--inventory[plr][object] = inventory[plr][object] + counter
table.insert(inventory[plr],{item = object,count = 1})
--inventory[plr][object] = 1
print(object.." Did not exist, created value")
end
function invfunction:AddPlayer(plr)
if not plr then
warn("Not a player, returning")
return
end
if inventory[plr] then
warn("Player already exists, returning")
return
end
inventory[plr] = {}
print("Created inventory")
end
function invfunction:Get(plr)
if not plr then
warn("Not a player, returning nil")
return nil
end
if not inventory[plr] then
warn("Player doesn't exist, returning nil")
return nil
end
return inventory[plr]
end
return invfunction
Like I said, when.I print the results in the module script, it shows them but outside it has no values inside the inventory table.