Ok so like I'm making a inventory I got it setup so that it something to your inventory. But I cant figure out how to make it cap out my current systems loops through everything in the inventory and then when it finds a item with the same name and adds its amount. But now I gotta check if its below 50 before adding it and then also if it goes above 50 when adding I gotta make a new iventory block thingy and add that to it. Im sorry of this is to complicated im bad at explaining this is the code I wrote recently idk if it helps. Thanks in advance!

local AddInv = game.ReplicatedStorage.RemoteEvents.AddInv


local RemoveInv = game.ReplicatedStorage.RemoteEvents.RemoveInv

function AddItem(Amount, ObjName, ImageID, CanEquip)

for i, items in pairs(script.Parent.ItemLayout:GetChildren()) do

	print(ObjName)

	if items.Name == ObjName and items.Amount.Value < 50 then

		items.Amount.Value = items.Amount.Value + Amount

		print("Added amount")

		if items.Amount.Value > 50 then

			local OverAmount = items.Amount.Value - 50

			items.Amount.Value = 50

			for i, leftovers in pairs(script.Parent.ItemLayout:GetChildren()) do

				if OverAmount ~= nil and leftovers.Name == ObjName and 

					leftovers.Amount.Value < 50 and leftovers.Amount.Value ~= 50 then

					print("leftover found")

					leftovers.Amount.Value = leftovers.Amount.Value + OverAmount
				else
					print("No leftovers creating new")
					local NewItem = script.Parent.ItemLayout.ItemBoxEx:Clone()

					NewItem.Parent = script.Parent.ItemLayout

					NewItem.Name = ObjName

					NewItem.Amount.Value = Amount	

					NewItem.ItemImage.Image = ImageID

					NewItem.EquipAble.Value = CanEquip

				end
				break
			end
		end
	else
		print("Not found creating new")
		local NewItem = script.Parent.ItemLayout.ItemBoxEx:Clone()

		NewItem.Parent = script.Parent.ItemLayout

		NewItem.Name = ObjName

		NewItem.Amount.Value = Amount	

		NewItem.ItemImage.Image = ImageID

		NewItem.EquipAble.Value = CanEquip

		break
	end
end

end