I’m currently working on an inventory system and ran into a weird problem. I’m using a module script to store all the item info which looks like this:
local module = {
["Apple"] = {
["Name"] = "Apple",
["Amount"] = 0,
["Slot"] = 0,
["Stackable"] = true,
["Id"] = nil,
}
}
return module
When accessing/requiring the module I’m doing this:
local InventoryFunctionsModule = require(InventoryModules.InventoryFunctions)
local function CreateItem(itemName)
local defaultItemInfo = ItemInfoModule[itemName]
table.insert(playerInventory, defaultItemInfo)
defaultItemInfo.Id = HttpService:GenerateGUID(false)
end
Now what happening is that when I’m modifying the defaultItemInfo it actually changes the contents of the module:
defaultItemInfo.Id = HttpService:GenerateGUID(false)
So doing that actually changes the “Id” in the ModuleScript. I even printed it on a whole other script, and it still printed the Id instead of the default value, nil.
From my understanding, you can’t modify what’s inside a ModuleScript from another script so I’m totally confused. I even tried requiring the module inside the function and it still changed what’s inside. I might be missing something totally obvious, but I have no clue what to do.