Help with getting gamepasses a user is selling

– This part has been solved, for the most part.
So, im attempting (for fun and to learn) to make a game similar to pls donate, where players have stands where they can sell their created gamepasses.

I have a system which gets a users gamepasses that are for sale, but it is VERY slow, like 40 seconds loading time, which i dont want.

pls donate seems to have immediate loading of the gamepasses, and i was wondering how they do this, and how i could modify the script im using to be faster.

The code im using is a slightly modified version of the code in this post.

local http = game:GetService("HttpService")

local Gamepass_baseUrl = "https://www.roproxy.com/users/inventory/list-json?assetTypeId=34&cursor=&itemsPerPage=100&pageNumber=%s&userId=%s"

module.getUserCreatedGamepassesRecursive = function(userId, gamepasses, pageNumber, lastLength)
	gamepasses = gamepasses or {}
	pageNumber = pageNumber or 1
	lastLength = lastLength or math.huge

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

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

		if success2 and result2 then
			for _, gamepass in ipairs(result2.Data.Items) do
				if gamepass.Creator.Id == userId then
					table.insert(gamepasses, gamepass.Item.AssetId)
				end
			end

			if result:len() ~= lastLength then
				lastLength = result:len()
				pageNumber += 1
				module.getUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
			end
		else
			warn(result)
			module.getUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
		end
	else
		warn(result)
		module.getUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
	end

	-- Remove gamepasses that arent for sale (I think, i barely understand this myself)
	for i, v in pairs(gamepasses) do
		if not game:GetService('MarketplaceService'):GetProductInfo(v, Enum.InfoType.GamePass).IsForSale or not game:GetService('MarketplaceService'):GetProductInfo(v, Enum.InfoType.GamePass).CanBeSoldInThisGame then
			table.remove(gamepasses, table.find(gamepasses, v))
		end
	end

	return gamepasses
end

It would be good for me to mention this:
I did look at other posts on the devforum, searched youtube, but i couldnt find anything i could understand.
If you could possible avoid making posts like this and instead, explain the of everything so my stupid brain can figure it out, that would be greatly appreciated.

I have attempted to use the post i linked as a bad example of what to respond with, and i have gotten nowhere with it. Just errors or constant failing.

--Gets the games which i then get gamepasses from, there has to be a better way, right?
local Base_URL = 'https://games.roblox.com/v2/users/%7Bid%7D/games?accessFilter=Public&limit=50'
module.getUserCreatedGamepassesRecursive_V2 = function(Player)
	-- what am i supposed to do here?
	--I tried formatting the string, got an error: ServerScriptService.Gamepass_Functions:57: invalid option '%B' to 'format'
	local requestUrl = '???'
	
	-- am i even doing this right?
	local success, result = pcall(function()
		return http:GetAsync(requestUrl)
	end)
	
	if success and result then
		return result
	else
		-- keeps returning false when it does work
		return false
	end
end

And now, here is the new problem.
With my code slightly modified, it is a lot faster now, but instead of displaying only gamepasses, the game is displaying everything the player owns or something like that.

What part of the code is making it cause such a long wait time?

Are you sure there is no other external factors playing in why it takes long time to retrieve the data, it could maybe be your internet or you maybe run the function too much which restricts how much information can be sent at once

Im on the best provider in my country, i doubt its the conection.
In fact, i do think i found why it takes so long, and managed to get the time from around 40 seconds down to an average of 15 seconds.

As this line stopped most gamepasses that arent for sale from appearing, it was the primary part of the code slowing down the entire script.
image

However, i have now run into another problem.

This is a screenshot of all the gamepasses my account is selling


As you can see, there are only 7 gamepasses.

However, the game is displaying a large number of 93 items.
What i believe is happening, is that the game is instead of displaying gamepasses and only gamepasses, it is instead displaying EVERYTHING the player has purchased.
With prices ranging from 1 to 10,000, it is very clear that something is wrong.
image

I did see something about roproxy not being used anymore, which is what the code i used uses, which i believe is the problem.

So i now need to get different code as the game isnt displaying anything correctly now.

Yes marketplace is a pretty heavy service to use, for your other issue of displaying all owned game passes what if you just compare if the gamepass was created by you and if not then not insert it into the array?

Well, upon further testing (and a few more modifications) i was able to limit the showing gamepasses to ones that ONLY the player has made.

However, the bad thing, the game is displaying passes that arent for sale.

I even have a check to see if the pass is for sale, but they still show up.
And CanBeSoldInThisGame isnt a variable for whatever reason as well, so i cant use that.

if gamepass.Creator.Id == Player.UserId and gamepass.Item.AssetType == 34 and gamepass.Product.IsForSale then
	table.insert(gamepasses, gamepass.Item.AssetId)
end

I tested the code and it seems to work, why don’t you as well use the userid passed onto the function in variable ‘userId’? Try running few prints as well to make sure all selection statements are actually true

Well, i believe i know what my problem is, i think.
I have archived a lot of games with gamepasses on them, and they were listed for sale.

Wouldn’t that automatically archive the gamepaswses along with it?, if not just set those gamepases offsale and it should be fine then