Good Day everyone,
I have been trying to make a building game with an inventory system, where the item data is stored in one module script and the the inventory data in an other. The module script that stores the inventory data has a function called UI (update inventory)
local BD = game.ReplicatedStorage.BlockData
local inv = {
}
function inv.UI(T) -- Update Inventory
local t = {}
for i, v in ipairs(inv) do
local d = require(BD)[v["N"]]
if T then
if require(BD)[v["N"]]["T"] ~= T then
continue
end
end
print(d["N"]) -- Problem ----------------------
local n = d["N"]
local m = d["M"]
local a = v["A"]
table.insert(t, {
["N"]=n, ["M"]=m, ["A"]=a
})
end
return t -- returns to local script where the information is used
end
return inv
BD (in replicated storage) is block data and it’s stored like this:
["Asphalt"] = {
["N"] = "Asphalt", -- Name
["T"] = "Block", -- Type
["S"] = 8, -- Strenght
["M"] = B.Asphalt -- Model
},
["Bassalt"] = {
["N"] = "Bassalt",
["T"] = "Block",
["S"] = 8,
["M"] = B.Bassalt
} -- etc...
And the data is put in the inv (inventory) like this:
{
["N"] = "WoodPlanks", -- Name
["A"] = 10 -- Amount
},
{
["N"] = "Rock",
["A"] = 5
}
So the problem is: when I run the script it prints d[“N”] being Grass in this case. But also gives the error attempt to index nil with “N”.
I’ve tried fixing the problem on various ways but it just doesn’t make sense.
thank you.