Why is this returning multiple of the same asset/product?

I’m working on a Tip System, and when adding the found items/assets/gamepasses from the request, I find that multiple of the same asset are added, for a reason I don’t understand.

This is the entire function for the tips.

-- The getUserAssetsRecursive was made by someone else, and has been altered to suit my purpose
local http = game:GetService("HttpService")

local function getUserAssetsRecursive(AssetId, userId, assets, pageNumber, lastLength)
	local baseUrl = "https://www.roproxy.com/users/inventory/list-json?assetTypeId="..AssetId.."&cursor=&itemsPerPage=100&pageNumber=%s&userId=%s"

	assets = assets or {}
	pageNumber = pageNumber or 1
	lastLength = lastLength or math.huge

	local requestUrl = baseUrl:format(pageNumber, userId)
	
	local success, result = pcall(function()
		return http:GetAsync(requestUrl)
	end)

	if success then
		if result then
			local success2, result2 = pcall(function()
				return http:JSONDecode(result)
			end)

			if success2 then
				if result2 then
					for _, asset in ipairs(result2.Data.Items) do
						if asset.Creator.Id == userId then
							if asset.Product.IsForSale == true then
								table.insert(assets, {asset.Item.AssetId, asset.Product.PriceInRobux})
							end
						end
					end

					if result:len() ~= lastLength then
						lastLength = result:len()
						pageNumber += 1
						getUserAssetsRecursive(AssetId,userId, assets, pageNumber, lastLength)
					end
				end
			end
		end
	end
	return assets
end

local function GetUserCreatedAssets(UserId : number,Assets : table)
	local createdAssets = {}

	for _,enum in pairs(Assets) do
		local info = getUserAssetsRecursive(enum.Value,UserId)
		createdAssets[enum.Name] = info
	end

	return createdAssets
end

function RefreshTips(Player)
	local AssetTypesRequested = {Enum.AssetType.Shirt, Enum.AssetType.TShirt, Enum.AssetType.GamePass}
	local data = GetUserCreatedAssets(Player.UserId, AssetTypesRequested)
	
	local NewTipTable = data
	
	for CategoryName, Category in pairs(NewTipTable) do
		local function SortFunction(a, b)
			local aPrice = a[2]
			local bPrice = b[2]
			return aPrice < bPrice
		end
		table.sort(Category, SortFunction)
	end
	
	print(NewTipTable)
	
	local success, errorMessage = pcall(function()
		TipData:SetAsync(Player.UserId, data)
	end)
	if not success then
		print(errorMessage)
		return false
	else
		return NewTipTable
	end
end

Output:
image

As you can see, there are more than one of the 10 Robux option with the ID 8946023526.
There seems to be 3 of each asset, when I only want one.

Any help would be appreciated.

2 Likes

Are their any errors in the output?