Hi there!
I am making a donation game with a friend but the script to get gamepasses from a player broke.
This script is a module and a server script run it. I don’t get any error messages but It don’t detect my gamepasses. (It return an empty table)
I use a print() and it say the function GetUserCreatedGamepassesRecursive(userId) run four time.
Can you help me please? I can’t finish the game until this script is fixed.
HttpService = game:GetService("HttpService")
return function(player)
-- roblox api thing (make sure to enable http access in setting else ur shit dont work)
local userId = player.UserId
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)
-- if parms not entered lol
gamepasses = gamepasses or {}
pageNumber = pageNumber or 1
lastLength = lastLength or math.huge
local requestUrl = baseUrl:format(pageNumber, userId) -- format url with image and page number
local success, result = pcall(function()
return HttpService:GetAsync(requestUrl) -- get request json file
end)
if success then
if result then
local success2, result2 = pcall(function()
return HttpService:JSONDecode(result) -- decode json to roblox table
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) -- add to table if player made the item
end
end
if result:len() ~= lastLength then -- if u need more result go to next page of items users has
lastLength = result:len()
pageNumber += 1
GetUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
end
end
else
warn(result)
GetUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength) -- run again
end
end
else
warn(result)
GetUserCreatedGamepassesRecursive(userId, gamepasses, pageNumber, lastLength)
end
return gamepasses
end
return GetUserCreatedGamepassesRecursive(userId)
--print(#userGamepasses)
--for _, gamepassId in ipairs(userGamepasses) do
-- print(gamepassId) -- easy
--end
end