Looking for a good way to store players items

Hello, I’m looking for a good way to store players items. I’ve decided to use module scripts, and I already have an inventory system created. Here’s the inventory system I’ve made so far:

local Inventory = {}
Inventory.__index = Inventory

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Signal = require(ReplicatedStorage.Packages.Signal)

function Inventory.new(Player)
	local self = setmetatable({}, Inventory)
	self.Items = {}
	self.ItemAdded = Signal.new()
	return self
end

function Inventory:Add(Item)
	if not self.Items[Item] then
		table.insert(self.Items, Item)
		self.ItemAdded:Fire(Item)
	end
end

return Inventory

I want the item to preferably stored like this:

Inventory = {
   ["Ring"] = {
        DamageBoost = 1.50,
        ManaBoost = 1.20,
   }
}

Any ideas on how I could structure my item system? any help will be appreciated.

function Inventory:Add(Name,Item)
	if not self.Items[Name] then
		self.Items[Name] = Item
		self.ItemAdded:Fire(Item)
	end
end
local inventory = Inventory.new()
local item = {
	DamageBoost = 1.50,
	ManaBoost = 1.20
}
inventory:Add("Ring",item)

i know your using oop to create a inventory class but isnt easier to just keep it as a module script

But using oop it would be written as:
…lua
function Inventory:Add(Name,Item)
if not self.Items[Name] then

	self.Items[Name] = {}
	self.ItemAdded:Fire(Item)
end

end

I just fixed his code by doing this:

function Inventory:Add(Item, Attributes)
	if not self.Items[Item] then
		self.Items[Item] = Attributes -- Store attributes in dictionary format
		self.ItemAdded:Fire(Item, Attributes)
	end
end

k cool that works better for your script

isn’t that the same as my script, just changing the name of the parameters around?

Yeah, I realised it was the essentially the same thing.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.