im trying to get the type of the item in my dictionary i made but it keeps returning nil even tho it it is there. the error is attempt to index nil with ‘Type’
local script
local function LoadInventory()
ClearInventory()
local buttonsCreated = 0
for id, amount in pairs(invData) do
local itemInfo = localModule.GetItemInfo(id)
if itemInfo.Type.Stackable then
CreateInventoryButton(itemInfo.Image, amount)
buttonsCreated += 1
else
buttonsCreated += amount
for i=1, amount do
CreateInventoryButton(itemInfo.Image, "")
end
end
end
for i=buttonsCreated+1, 20 do
CreateInventoryButton("", "")
end
end
module script
local itemTypes = {
Potion = {
Stackable = true,
MaxStack = 10
},
Equipment = {
Stackable = false
}
}
local itemsInfo = {
["1"] = {
Name = "Potion",
Image = "rbxassetid://7862622341",
Type = itemTypes.Potion,
Description = "amogus potion"
},
["2"] = {
Name = "Sword",
Image = "rbxassetid://7863601994",
Type = itemTypes.Equipment,
Description = "amogus sword"
}
}
function module.GetItemInfo(id)
return itemsInfo[id]
end
Then, the only other problem I could think of is the fact that it gets the information off of the id, meaning the id isn’t the same as you are passing. What exactly are you passing? If it is a number for the id, you would need to use tostring() to turn it into a string for it to return.