I’m currently having an issue with my ModuleScript and a own created function. When I try to autosave the data in a datastore I loop trough all values in the module script table. The following function somehow appears as a key in the table. (I minimized the Script a bit)
local Inventories = {}
function Inventories.AddItem(Player, SlotValue, ItemData)
local PlayerUserId = "Player_".. Player.UserId
if not Inventories[PlayerUserId] then
Inventories[PlayerUserId] = {}
end
local Inventory = Inventories[PlayerUserId]
Inventory[SlotValue] = ItemData
return true
end
local function saveOnExit(Player)
local PlayerUserId = "Player_".. Player.UserId
savePlayerData(PlayerUserId)
for PlayerUserId, data in pairs(Inventories) do
print(PlayerUserId, #data)
-- output --> AddItem nil
end
end
return Inventories
I would like to have a solution where the function no longer appears as a key in the table and can be also called with require in another script.
Just for example what I mean with require in the another script:
local ModuleScript = require(Path.ModuleScript)
local function AddItem(Player, ItemData)
ModuleScript.AddItem(Player, SlotValue, ItemData)
end