Detecting whether an inventory is full

I have an inventory system:

Module

local StackLimits = require(workspace.StackLimits)
local Inventory = {}

local Item
local Amount
local MAX_SLOTS = 28
local i = 1
Inventory.__index = Inventory

function Inventory.new(player)
	local self = {}

	self.Player = player
	self.NumSlots = 0
	self.Data = {}
	return setmetatable(self, Inventory)
end

function Inventory:AddItem(args)

		if args["Item"..i] then 
			
			Item = args["Item"..i]
			Amount = args["Num"..i]
			
			if self.Data[Item] then
				self.Data[Item] += Amount
			else
				self.Data[Item] = Amount
				self.NumSlots += 1
			end
		else
			script.Parent.AddComplete:Fire()
		end
		i+=1

end

function Inventory:StackFixer(args)
	if self.Data[Item] > StackLimits[Item] then

		local TotalFullStacks = math.floor(self.Data[Item]/StackLimits[Item])
		local Remaining = self.Data[Item] % StackLimits[Item]

		if Remaining > 0 then
			self.NumSlots += (TotalFullStacks + 1)-self.NumSlots
		else
			self.NumSlots += TotalFullStacks-self.NumSlots
		end
	end
	print("Inventory now has "..self.NumSlots.." slot(s) occupied")
end

function Inventory:FullFixer(args)
	
end
return Inventory

Server:

local StackLimits = require(workspace.StackLimits)
local Inventory = require(script.Inventory)
local InventoryTables = {}

local function CreateNewInventory(Player)
	local ID = Player.UserId
	local inventory = Inventory.new(ID)
	InventoryTables[ID] = inventory
end

game.Players.PlayerAdded:Connect(CreateNewInventory)
game.ReplicatedStorage.Inventory.AddItemBindable.Event:Connect(function(player,args)
	local Inventory = InventoryTables[args.PlayerID]
	Inventory:AddItem(args)
	Inventory:StackFixer(args)
	print(Inventory)
end)

I need to fill in the FullFixer() function so that it will check to see if the slots have gone over the limit and the part I cannot figure out is how to figure out how many items went over the limit.

2 Likes