So I really confused right now. I have a module that adds items to the inventory but there is an issue, whenever I check the quantity the output says nil
. I tried checking this with other stats like health and they print 0
. I use quantity to check if they own it as well as how much of that item they have.
give.Give = function(tool, tablearea, player, equiptable) -- Tool being weapon/armour/potions / Tablearea being Weapons.WeaponTable
for num, item in pairs(ReplicatedStorage[tool]:GetChildren()) do -- Checks all the weapons in the weapons folder
for serial, name in pairs(tablearea) do -- Checks table
print(tablearea[serial].Quantity) -- test it prints out nil
if item.Name == tablearea[serial].Name and tablearea[serial].Quantity > 0 then -- if they own it // The value in quantity is 0
print(item)
if item.Stats.Serial.Value == serial then -- Checks to see if it's the correct serial
for ser, itm in pairs(equiptable) do
if serial == equiptable[tool] then
print("You made it here!")
local humanoid = player.Character:FindFirstChildOfClass("Humanoid")
local weap = item:Clone()
humanoid:EquipTool(weap)
end
end
for i = 1,name["Quantity"] do
--print("We made it here")
adding.AddedEvent(item, tool, player)
end
end
end
end
end
end
This is the table for the weapons:
local Weapons = {}
Weapons.WeaponsTable = {
[1] = {
["Name"] = "Wooden Sword",
["Damage"] = 5,
["Magic Damage"] = 2,
["Health"] = 0,
["Rarity"] = "Common",
["Quantity"] = 5
},
[2] = {
["Name"] = "Wooden Sword",
["Damage"] = 7,
["Magic Damage"] = 4,
["Health"] = 0,
["Rarity"] = "Common",
["Quantity"] = 0
},
[3] = {
["Name"] = "Wooden Sword",
["Damage"] = 10,
["Magic Damage"] = 5,
["Health"] = 0,
["Rarity"] = "Common",
["Quantity"] = 0
},
[4] = {
["Name"] = "Wooden Sword",
["Damage"] = 13,
["Magic Damage"] = 7,
["Health"] = 2,
["Rarity"] = "Common",
["Quantity"] = 0
},
[5] = {
["Name"] = "Stone Sword",
["Damage"] = 5,
["Magic Damage"] = 2,
["Health"] = 0,
["Rarity"] = "Common",
["Quantity"] = 0
},
-- [2].. [3].. [4].. and so on.
}
return Weapons
So if anyone can tell me why it prints nil, that would be really helpful. Thank you!
Edit:
If i use print(tablearea[serial].Quantity)
it will print nil.
If i use print(tablearea[serial].Health)
it will print 0.
So why does Quantity output nil.
If there are any replies, I may not be able to see them as I need to sleep. As soon as I am back on I will reply and try any suggestions that are posted. Thank you.