I want to make an inventory system, but I don’t know how I would make it or how I could script it either, do you have any ideas on how I could make an inventory system?
First, you need to know how to use datastores
Second, you need to know how to store and edit tables
I recommend that you make a module for storing and editing the data which in this case would be inventories
Thats all you need to know tbh.
Ok, thankfully I do know all of that, the problem is I don’t know how I would make how it would work the “logic”.
By logic, if you mean a method or ways to design it. If so I have two favorite ways I can probs share.
Would you like to see some example code of how I edit tables?
I’d prefer to see your two favorite ways of designing it or the method you have.
But seeing how you edit tables would be nice, to see if I could learn anything more.
First method I will show I refer to as the stack method when I store things in my to preserve space I give them special ID’s A letter and a number and i make a module for doing so
Image of Items module
Stack Method
Since the items wont have any data within them I just place em under 1 index and give that index a integer
function InventoryManager:AddItem(Player,ItemID,Amount)
local Profile = DataManager:GetInventoryProfile(Player) -- ProfileService Module
local Items = Profile.Data.Items
if Amount == nil then Amount = 1 end
if Items[ItemID] then
Items[ItemID] = Items[ItemID] + Amount
else
Items[ItemID] = Amount
end
end
Other method
This method is for complex objects that have data like levels (let’s just say in my game the weapons will have levels)
function ArmoryManager:Add_Weapon(Player,ID)
local Profile = DataManager:GetArmoryProfile(Player)
local Arsenal = Profile.Data.Arsenal
local WeaponAmount = table.getn(Arsenal)
local WeaponTable = Weapons.Get_Weapon_FromID(ID)
if WeaponAmount <= 49 then
local GUID = HttpService:GenerateGUID(false) -- Generates a unique ID
local Unique_ID = ID.. '#'..GUID
local Weapon = {}
Weapon.ID = Unique_ID -- To tell the Unique weapons apart
Weapon.R = 1 -- Rank
Weapon.SG = {} -- Sigils
Weapon.E = 0 -- Experience
if WeaponTable.WeaponClass and WeaponTable.WeaponClass.Spells then -- Checks my weapon type incase i wanna give em ability to equip spells to there weapon
Weapon.SP = {}
end
print(Weapon)
table.insert(Arsenal,WeaponAmount+ 1,Weapon)
end
end```
if you have any questions just ask I will be happy to go more in-depth and elaborate