Whats up. I was wondering around the DevForum and I saw a script. This script is supposedly supposed to print out all of the ID’s a user has created. What I want to know is how does this script work, could there be any senarios where the script doesn’t work, and other information that could be useful for me to know. I’m asking this because I’m interested in how games like PLS DONATE and STARVING ARTISTS work and function. Here is the script:
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
This is a script for retrieving a user’s created game passes using the RoProxy API. Here’s a brief overview of how the script works:
The script gets a reference to the HttpService, which is a Roblox service that allows HTTP requests to be made from within a game. The baseUrl variable contains a URL template for the RoProxy API endpoint that returns a JSON list of game passes for a given user ID. The getUserCreatedGamepassesRecursive function is defined to recursively retrieve all of a user’s created game passes using the RoProxy API. The function takes in the user ID, an optional list of game passes, an optional page number, and an optional last length parameter. Inside the function, the http:GetAsync method is used to make an HTTP GET request to the RoProxy API endpoint with the appropriate URL for the current page number and user ID. The result of the request is stored in the result variable. If the request was successful (i.e., pcall returned true), the result is then decoded from JSON format into a Lua table using the http:JSONDecode method. The resulting table contains information about the user’s game passes. The script then iterates over each game pass in the table, and if the game pass’s creator ID matches the user ID, it adds the game pass’s asset ID to the gamepasses list. The script then checks if the length of the result string has changed from the last time the function was called. If it has not changed, then there are no more game passes to retrieve, and the function returns the gamepasses list. If there are more game passes to retrieve, then the function recursively calls itself with an incremented page number and the current gamepasses list. Finally, the script calls the getUserCreatedGamepassesRecursive function with a user ID of 2032622, which retrieves all of that user’s created game passes. The script then prints the total number of game passes retrieved (#userGamepasses), followed by each game pass ID in the list.
Overall, this script demonstrates how to use the RoProxy API and the HttpService in Lua to retrieve information about a user’s game passes.