Assigned variable printing out multiple variables

You can write your topic however you want, but you need to answer these questions:
I want to make so when someone clicks on a new image button in their inventory, they can use a amount box to change the amount of what item they want to buy, but when someone uses or clicks on the amount box it prints out multiple names of items depending which one you clicked on, also when you click or change the amount box the price of the item changes to the basic first item in the game that is selected when you open the gui.

	for _,i in pairs(items:GetChildren()) do
		if category == im.GetType(i.ItemType.Value) then
			if i.Tier.Value <= 8 then
				local realitem = game.ReplicatedStorage.Items[i.Name]
				local desc = script.Parent.Shop.Desc
				local amountbox = script.Parent.Shop.Desc.Amount
				local image = Instance.new("ImageButton")
				local amount = 1
				image.Name = i.Name
				image.Image = "rbxassetid://"..realitem.ThumbnailId.Value
				image.BorderSizePixel = 0
				image.Parent = script.Parent.Shop.Items
				
				image.MouseButton1Click:connect(function()
					desc.Visible = true
					desc.ImageBC.BackgroundColor3 = tm.TierColor(realitem.Tier.Value)
					desc.Called.Text = realitem.Name
					amountbox.Text="1"
                    local itemname = game.ReplicatedStorage.Items:FindFirstChild(image.Name)
					desc.Called.TextColor3 = tm.TierColor(realitem.Tier.Value)
					desc.Tier.Text = tm.GetTier(realitem.Tier.Value)
					desc.Tier.TextColor3 = tm.TierColor(realitem.Tier.Value)
					desc.Description.Text = realitem.Description.Value
					desc.ImageBC.ImageLabel.Image = "rbxassetid://"..realitem.ThumbnailId.Value
					desc.Buy.Text = "Buy x"..maths.GetSuffixNotForCash(amount).." - "..maths.GetSuffix(itemname.Cost.Value * amount)
					desc.Close.MouseButton1Click:connect(function()
						desc.Visible = false	
					end)
					amountbox.Changed:connect(function()
					itemname = game.ReplicatedStorage.Items:FindFirstChild(image.Name)
                                          print(itemname.Name) -- HERE IS THE PROBLEM IT SHOWS ALL THE ITEMS THAT THE USER HAS CLICKED ON WHEN IT PRINTS THE NAME OUT
					local rawamount = tonumber(amountbox.Text)
					if rawamount ~= nil then
							amount = rawamount
							
					else
							amount = 1
							
						end
						
						desc.Buy.Text = "Buy x"..maths.GetSuffixNotForCash(amount).." - "..maths.GetSuffix(itemname.Cost.Value * amount)
						
					end)
1 Like