I don’t think I would be much of a help.
There’s many different ways to create an inventory, so I’ll just give you general tips that can be applied to any system you want to make. First off, I recommend with keeping the inventory structure in Lua, then later reading that data to display in your GUI. Keep your inventory data and GUI separate!
If you want the short version of the following information, scroll all the way to the bottom.
Cell storage: Each cell is just another table in a table inside of a ModuleScript. I’ll use this as an example:
local inventory = {
[1] = {
["ID"] = 1,
["Quantity"] = 831,
},
[5] = {
["ID"] = 2,
["Quantity"] = 43,
}
}
-- usage: itemInformation[Item ID]
local itemInformation = {
[1] = {Other useful info}
}
local firstItemSlot = inventory[1]
local firstItemInfo = itemInformation[firstItemSlot.ID] -- item info
At slot 1, we can get the item’s information through its ID, as well as the quantity of that item in the slot. With the ID, we can get other information about the item, such as the max stack, in a different table.
You can manipulate the data afterwards, which is what I believe is the most complex and specific part.
Manipulation: This part requires knowledge of how to manipulate data in a table. For example, if you want to swap slots, here is what you would do…
local function swapSlots(firstIndex: number, secondIndex: number)
-- Not optimized at all, just a general idea
-- First we get their references
local firstItem = inventory[firstIndex]
local secondItem = inventory[secondIndex]
-- Now, move them
inventory[secondIndex] = firstItem
inventory[firstIndex] = secondItem
end
Representation: Whenever a slot is modified, we should tell the inventory GUI that it needs to update those slots. How it’s represented depends on you.
Networking: I haven’t gotten to this part yet, but what I’m doing is manipulating the inventory through the client and not replicating that to the server. You can do sanity checks on the server, such as if it’s impossible for an item to be picked up or if the item is even in the inventory.
TL;DR
- Store your inventory as a table
- Each item in your inventory should have an ID associated with it
- Manipulation of the inventory is just manipulating a table
And as a warning, working on the inventory alone took around 10 hours for me.