How do I check for multiple of the same item?

Hi there! I’m making an inventory system and I want to check if there are multiple items of the same type obtained so i can make a item count instead of having multiple frames of the same item

local function clickDetectorHandler(clickDetector, highlight)
	local box = clickDetector.Parent
	local boxHealth = box:FindFirstChild("Health")
	local boxMaxHealth = box:FindFirstChild("MaxHealth")
	local healthIndicator = box:FindFirstChild("HealthIndicator")

	clickDetector.MouseHoverEnter:Connect(function()
		highlight.Enabled = true
	end)

	clickDetector.MouseHoverLeave:Connect(function()
		highlight.Enabled = false
	end)

	clickDetector.MouseClick:Connect(function()
		local randomSound = Sounds.BoxHit:GetChildren()
		local random = math.random(1, #randomSound)
		local chosenSound = randomSound[random]
		
		healthIndicator.MainFrame.HealthIndicator.BoxHealth.Text = boxHealth.Value .. "/" .. boxMaxHealth.Value
		healthIndicator.MainFrame.BoxName.Text = box.Name

		chosenSound:Play()
		
		if boxHealth.Value > 0 then
			BoxRemotes.BoxDamaged:InvokeServer(box)
		elseif boxHealth.Value <= 0 then
			BoxRemotes.BoxOpened:FireServer(box)
			Headline.InventorySize.Text = currentInvSpace.Value.."/"..maxInvSpace.Value
			
			wait(.1)
			
			local clone = RewardFrame:Clone()
			clone.Parent = ui
			local itemImage = clone.ItemImage
			local sparkles = clone.Sparkles
			local itemName = clone.ItemName
			local rarity = clone.Rarity
			
			for i, item in pairs(Inventory:GetChildren()) do
				local itemName_ = item.Value
				itemName.Text = itemName_
				if item:IsA("StringValue") then
					for i ,v in pairs(Items:GetDescendants()) do
						if v.Name == itemName_ then
							itemImage.Image = v.Value
						end
					end
				end
			end
			
			clone:TweenSize(UDim2.new(0,471,0,471), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, .5, true)
			itemImage:TweenSize(UDim2.new(0,471,0,471), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, .5, true)
			sparkles:TweenSize(UDim2.new(0,471,0,471), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, .5, true)
			itemName:TweenSize(UDim2.new(0, 256,0, 50), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, .5, true)
			rarity:TweenSize(UDim2.new(0, 151,0, 26), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, .5, true)
			Sounds.ItemReward:Play()
			
			for i=1, 100 do
				wait(.0001)
				sparkles.Rotation += 1
			end
			
			clone:TweenSize(UDim2.new(0,0,0,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, .2, true)
			itemImage:TweenSize(UDim2.new(0,0,0,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, .2, true)
			sparkles:TweenSize(UDim2.new(0,0,0,0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, .2, true)
			itemName:TweenSize(UDim2.new(0, 0,0, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, .2, true)
			rarity:TweenSize(UDim2.new(0, 0,0, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, .2, true)
			
			wait(1.5)
			clone:Destroy()
		end
	end)
end

local function boxHandler()
	for i, v in pairs(Boxes:GetDescendants()) do
		if v:IsA("UnionOperation") then
			local clickDetector = Instance.new("ClickDetector")
			clickDetector.Parent = v

			local highlight = Instance.new("Highlight")
			highlight.Parent = v
			highlight.Enabled = false	
			highlight.FillTransparency = 1
			
			local clone = healthIndicator:Clone()
			clone.Parent = v
			clone.Adornee = v
			clone.MainFrame.HealthIndicator.BoxHealth.Text = v.Health.Value .. "/" .. v.MaxHealth.Value
			clone.MainFrame.BoxName.Text = v.Name

			clickDetectorHandler(clickDetector, highlight)
			print(clickDetector, highlight)
		end
	end
end

boxHandler()

if tonumber(#Inventory:GetChildren()) < maxInvSpace.Value then
	Inventory.DescendantAdded:Connect(function(child)
		local InvClone = template_Inv:Clone()
		InvClone.Name = child.Name
		InvClone.ItemName.Text = child.Name
		InvClone.Parent = ItemDisplayer
	end)
elseif #Inventory:GetChildren() > maxInvSpace.Value then
	warn("Inventory is full!")
end

OpenButton.MouseButton1Click:Connect(function()
	Sound:Play()
	Headline.InventorySize.Text = currentInvSpace.Value.."/"..maxInvSpace.Value
	MainInventoryFrame:TweenPosition(UDim2.new(0.306, 0,0.164, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Quart, .2, true)
	
	for i, item in pairs(Inventory:GetDescendants()) do -- here I tried to check for multiple items
		if item:IsA("StringValue") then
			for i, compareitem in pairs(Inventory:GetDescendants()) do
				if compareitem:IsA("StringValue") and item ~= compareitem then
					if compareitem.Name == item.Name then
						for i, v in pairs(ItemDisplayer:GetChildren()) do
							if v:IsA("Frame") and v.Name == compareitem.Name then
								v.Count.Text = "x"
								v.Count.Visible = true
							end
						end
					end
				end
			end
		end
	end
end)

Do you get an error? You didn’t say what it is doing. If you don’t know what its doing, add print statements in all these places to find out: