Help with oop inventory system

I want to make my own Inventory system.

I cant figure out how to detect which slot the item that you picked up must go in.

I have tried checking if the slot is full but that hasn’t worked.

Code:

local Class = require(game.ReplicatedStorage.Classic)
local ServerStorage = game.ServerStorage


local Point = Class:extend()

local Items = {
	["Apple"] = script.Items:WaitForChild("Apple");
	["Fish"] = script.Items:WaitForChild("Fish");
	["Hotdog"] = script.Items:WaitForChild("Hotdog");
}

function Point:new(Slots)
	self.Slots = Slots or 1
	self.UsedSlots = 0
	self.Item = nil
end

function Point:AddItem(Item)
	if self.UsedSlots + 1 > self.Slots then return end
	if Item == self.Item or self.Item == nil then
		self.Item = Item
		self.UsedSlots = self.UsedSlots + 1
	end
end

function Point:GetSlotData()
	local Data = {
		Slots = self.Slots;
		UsedSlots = self.UsedSlots;
		Item = self.Item;
	}
	return Data
end

function Point:DropItem(Position)
	if self.Item then
		if self.UsedSlots - 1 ~= -1 then
			local ItemClone = Items[self.Item]:Clone()
			ItemClone.Parent = workspace
			ItemClone.Position = Position
			local PickUpScript = script.PickUpScript:Clone()
			PickUpScript.Parent = ItemClone
			self.UsedSlots = self.UsedSlots - 1
			if self.UsedSlots == 0 then
				self.Item = nil
			end
		end
	end
end

function Point:CanAdd(Item)
	--Check if the slot is has the same item or if it is empty.
end

return Point

please just use the search bar there are lots of topics discussing this

since you are in need of help here are topics that ask on how to make an inventory system,

1 Like

I already made an inventory system, I am asking how I can check to see what slot the item is suppose to go in.

UI GridLayout and Positioning and duplicating it everytime an object adds may be the solution for this

Wait I forgot to show the code, I edited the original post.

if you name the frame with the item name just do checks in if the item name has a similar frame name with it and then add quantity for that item

1 Like

Wow I am dumb I didnt know I was that simple:

function Point:CanAdd(Item)
	if self.Item == Item or self.Item == nil then
		return true 
	else 
		return false
	end
end