How to get player's all gamepasses with script?

I am working on creating a piggy bank tool for a game that allows players to open other people’s game passes and donate (same as the “pls donate” sign game pass which shows player’s game passes but this will have the frame in startergui to show it instead) with a proximity prompt, using a frame. I understand that I will need to use an API and a proxy in order to accomplish this task. However, I am not very familiar with those and have found that a script I found on a developer forum, which I believed would help me, is no longer functional. If anyone has knowledge or experience in this area and is able to assist me, I would greatly appreciate it. Thank you in advance for your help.

local http = game:GetService("HttpService")
local baseUrl = "https://www.roproxy.com/users/inventory/list-json?assetTypeId=34&cursor=&itemsPerPage=100&pageNumber=%s&userId=%s"
local function getUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
	gamepasses = gamepasses 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 _, 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
						getUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
					end
				end
			else
				warn(result)
				getUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
			end
		end
	else
		warn(result)
		getUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
	end
	return gamepasses
end

local userGamepasses = getUserCreatedGamepassesRecursive(2032622)
print(#userGamepasses) --6 gamepasses.
for _, gamepassId in ipairs(userGamepasses) do
	print(gamepassId) --6 gamepass IDs.
end
1 Like
local http = game:GetService("HttpService")
local baseUrl = "https://www.roproxy.com/users/inventory/list-json?assetTypeId=34&cursor=&itemsPerPage=100&pageNumber=%s&userId=%s"
local function getUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
	gamepasses = gamepasses 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 _, 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
						getUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
					end
				end
			else
				warn(result)
				getUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
			end
		end
	else
		warn(result)
		getUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
	end
	return gamepasses
end

local player = game.Players.LocalPlayer
local playerId = player.UserId
local userGamepasses = getUserCreatedGamepassesRecursive(playerId)

local frame = Instance.new("Frame")
frame.Name = "PiggyBank"
frame.Size = UDim2.new(0, 200, 0, 200)
frame.Position = UDim2.new(0.5, -100, 0.5, -100)
frame.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
frame.Parent = player.PlayerGui

local textLabel = Instance.new("TextLabel")
textLabel.Name = "Gamepasses"
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.Text = "Gamepasses:"
textLabel.TextColor3 = Color3.fromRGB(0, 0, 0)
textLabel.TextScaled = true
textLabel.Parent = frame

for _, gamepassId in ipairs(userGamepasses) do
	local gamepassButton = Instance.new("TextButton")
	gamepassButton.Name = "Gamepass"..gamepassId
	gamepassButton.Size = UDim2.new(1, 0, 0, 20)
	gamepassButton.Position = UDim2.new(0, 0, 0, 20)
	gamepassButton.Text = "Gamepass "..gamepassId
	gamepassButton.TextColor3 = Color3.fromRGB(0, 0, 0)
	gamepassButton.TextScaled = true
	gamepassButton.Parent = frame
end

(this plugin try to fix it)

I am also having the same issue, but with what I was testing, the roproxy only gets so much gamepasses the user has, and since the player can own gamepasses that aren’t theirs from buying it, their game passes they’ve created can get masked by it. The main issue isn’t really the scripts’ fault for what I know. the pageNumber part of roproxy isn’t working.