Why is my script returning the game id rather than gamepass id?

I have a script that should return a players gamepass id’s but for some reason its returning the place id’s. Any idea why this is?

                  local function GetUserGamepasses(winnerId)
						local userId = winnerId

						local gamepasses = {}
						local GetGamesUrl1 = "https://games.RoProxy.com/v2/users/"
						local GetGamesUrl2 = "/games?accessFilter=Public&sortOrder=Asc&limit=10"
						local getGamesUrl = GetGamesUrl1..userId..GetGamesUrl2

						local success,result = pcall(function()
							return Http:GetAsync(getGamesUrl)
						end)

						if success then
							pcall(function()
								result = Http:JSONDecode(result)
								for _,GameInfo in pairs(result["data"]) do
									local gameId = GameInfo.id
									local url = "https://games.RoProxy.com/v1/games/%s/game-passes?limit=100&sortOrder=Asc"
									url = url:format(gameId)

									local success2,result2 = pcall(function()
										return Http:GetAsync(url)
									end)

									if success2 then
										result2 = Http:JSONDecode(result2)
										for _,GamepassDetail in pairs(result2["data"]) do
											local gamepassId = GamepassDetail.id
											table.insert(gamepasses,gamepassId)
										end
									end
								end                               
							end)
						end                     

						return gamepasses
					end                                                                            
					
					local userTShirts = GetUserGeneratedTShirts(winnerId, 10)
					local userGamepasses = GetUserGamepasses(winnerId)
1 Like

The GetGamesUrl2 variable concatenates “/games?accessFilter=Public&sortOrder=Asc&limit=10” to the url constructed for fetching games. This suggests it’s supposed to fetch public games, but the subsequent code doesn’t directly check for game passes associated with these games. Instead, it seems to fetch game passes associated with the games IDs themselves.

local function GetUserGamepasses(winnerId)
    local userId = winnerId

    local gamepasses = {}
    local GetGamesUrl1 = "https://games.RoProxy.com/v2/users/"
    local GetGamesUrl2 = "/games?accessFilter=Public&sortOrder=Asc&limit=10"
    local getGamesUrl = GetGamesUrl1..userId..GetGamesUrl2

    local success,result = pcall(function()
        return Http:GetAsync(getGamesUrl)
    end)

    if success then
        pcall(function()
            result = Http:JSONDecode(result)
            for _,GameInfo in pairs(result["data"]) do
                local gameId = GameInfo.id
                local url = "https://games.RoProxy.com/v1/games/%s/game-passes?limit=100&sortOrder=Asc"
                url = url:format(gameId)

                local success2,result2 = pcall(function()
                    return Http:GetAsync(url)
                end)

                if success2 then
                    result2 = Http:JSONDecode(result2)
                    for _,GamepassDetail in pairs(result2["data"]) do
                        local gamepassId = GamepassDetail.id
                        table.insert(gamepasses,gamepassId)
                    end
                end
            end                               
        end)
    end                     

    return gamepasses
end

1 Like

Thanks, So how would I go about fixing this? Theres also this script which I tried but this also just returned the place Ids for some reason:

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)

the line if result:len() ~= lastLength attempts to check if the length of the result has changed since the last request. but result is already the decoded JSON object, so result:len() doesn’t make sense here,

also, you seem to have missed passing the correct arguments to getUserCreatedGamepassesRecursive when calling it recursively. You should also check whether the result2.Data.Items table exists before trying to iterate over it

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
        local success2, result2 = pcall(function()
            return http:JSONDecode(result)
        end)
        
        if success2 and result2 and result2.Data and result2.Data.Items then
            for _, gamepass in ipairs(result2.Data.Items) do
                if gamepass.Creator.Id == userId then
                    table.insert(gamepasses, gamepass.Item.AssetId)
                end
            end
            
            if #result2.Data.Items > 0 and #result2.Data.Items ~= lastLength then
                getUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber + 1, #result2.Data.Items)
            end
        end
    end
    
    return gamepasses
end

local userGamepasses = getUserCreatedGamepassesRecursive(2032622)
1 Like

I got the script from this guy, and everyone was saying it worked so I don’t know if its just an outdated method?

No, you just implemented it in a non-effective way, what I mean is you used result:len() to check the length of the result, but result is holding the JSON decoded data, you also did not add a condition to check if result2.Data.Items exists before iterating over it. The arguments you passed to the resursive call were incorrect aswell.

Ok, thanks, so would fixing this cause it to now return the gamepasses rather than the place ids?

yes, correct. it should return the gamepass ids

1 Like

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