Question about inventory system

I just have a quick question because I’m trying to make an inventory system

If I store the player’s items in a module script and have all the functions like add/remove in it too, would that be a good way to start it? Or should I do it a different way

Example:

local InventoryModule = {}


local inventory = {
	slot1 = "empty",
	slot2 = "empty",
	slot3 = "empty",
	slot4 = "empty",
	slot5 = "empty",
	slot6 = "empty",
	slot7 = "empty",
	slot8 = "empty",
	slot9 = "empty",
}



function InventoryModule.AddItem()
	
end

function InventoryModule.RemoveItem()

end

return InventoryModule

I was thinking I store the item names in the slots but I want to know the best way to go about it

This is a fine way to do it, but be aware that each module script is only loaded once, so this will only give you one inventory shared for each script that requires it. This would be perfect on the client but not useful on the server, since you wouldn’t be able to have multiple inventories for multiple players.

How would you go about getting an inventory for each player

You can have a function act as a factory for your inventories. This function can add other functions to the table either directly or via a metatable.

local InventoryModule = {}

function InventoryModule.CreateInventory()
	local inventory = {
		slot1 = "empty",
		slot2 = "empty",
		slot3 = "empty",
		slot4 = "empty",
		slot5 = "empty",
		slot6 = "empty",
		slot7 = "empty",
		slot8 = "empty",
		slot9 = "empty",
	}

	function inventory.AddItem()
		--Do stuff
	end
	
	function inventory.RemoveItem()
		--Do stuff
	end

	return inventory
end

return InventoryModule