NOTE: This retrives all of a user’s gamepasses, regardless of their inventory being private/public
Ever wanted to make a PLS Donate game? Well I did, so I made it.
Here’s how:
So, we’re not just going to get a user’s public gamepasses from their inventory. We will RETRIEVE EVERY GAMEPASS the player has created on their games.
Let’s begin.
(getting a user’s clothing is fairly simple, and there’s already tutorials on that, so I won’t be covering this.
local function getUserGamepasses(userId)
local url = "https://games.roproxy.com/v2/users/"..userId.."/games?accessFilter=2&limit=50&sortOrder=Asc"
local suc, res = pcall(function()
return HttpService:GetAsync(url)
end)
local placeIDs = {}
if suc then
if res then
res = string.split(res,"},")
for i, place in pairs(res) do
place = string.split(place,",")
for _, thing in pairs(place) do
if string.find(thing,"id") and not string.find(thing,"rootPlace") then
place = thing
place = string.gsub(place,"%a","")
place = string.gsub(place,"%p","")
table.insert(placeIDs,place)
end
end
end
end
end
local gamepasses = {}
local gamepassPrices = {}
local increment = 1
if #placeIDs > 0 then
for i, place in pairs(placeIDs) do
local url = "https://games.roproxy.com/v1/games/"..place.."/game-passes?limit=100&sortOrder=Asc"
local suc, res = pcall(function()
return HttpService:GetAsync(url)
end)
res = string.split(res,"}")
for x, gamepass in pairs(res) do
if string.find(gamepass,"id") then
local newPass = string.split(gamepass,",")
local productId = nil
local price = nil
for _, info in pairs(newPass) do
if string.find(info,"id") then
productId = info
productId = string.gsub(productId,"%a","")
productId = string.gsub(productId,"%p","")
end
if string.find(info,"price") then
price = info
price = string.gsub(price,"%a","")
price = string.gsub(price,"%p","")
end
end
if productId and price then
if not table.find(gamepassPrices,price) then
gamepasses[increment] = {
Item = {
AssetId = tonumber(productId)
};
Product = {
PriceInRobux = tonumber(price)
};
}
table.insert(gamepassPrices,price)
increment += 1
end
end
end
end
end
end
return gamepasses
end
What this does is it loops through all of a player’s games, then loops through each game’s gamepasses and adds them to a table.
After running the function (on server of course), it will return a table full of gamepasses. Each gamepass has its own little table containing the AssetId (so you can make the player buy it), and the price of the gamepass.
That’s about it, sorry if I didn’t explain it that well, but the code works and that’s really all that matters haha, nobody ever bothers to read this much either way.