Merging items in text to say Item.X(Amount)

  1. What do you want to achieve?
    Merge items in a table to show TestItemx2 instead of TestItem,TestItem
  2. What is the issue?
    i have no clue how to do this

Screenshot 2023-10-14 151814

local ItemsList = {}
	for _,item in pairs(workspace:GetPartsInPart(game.Workspace.Shops.MainShop.CounterBox)) do
		if item.Parent.Parent == game.Workspace.Objects.ShopItems then
			table.insert(ItemsList,item.Parent.Name)
		end
	end
	local TextTable = {}
	local text = nil
	for _,item in pairs(ItemsList) do
		if text == nil then
			text = item
		else
			text = text..","..item
		end
	end
	game.Workspace.Shops.MainShop.CounterBox.SelectionBox.Visible = true
	plr.PlayerGui.ShopGui.MainShop.Text.Text = "Would You Like To Buy "..text.." For ".."?".. "?"
	plr.PlayerGui.ShopGui.MainShop.Visible = true
2 Likes

Maybe Something like this?

local Tab = {"A","A","A","B"}

local function GetUniqueEntries(Tab)
	local Unique_Table = {}
	for i = 1, #Tab do
		Unique_Table[Tab[i]] = (Unique_Table[Tab[i]] or 0) + 1 
	end
	return Unique_Table
end

local UniqueCounts = GetUniqueEntries(Tab)

for Name,Count in pairs(UniqueCounts) do
	print(Name.."X"..Count)
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.