I was trying to make a donation game, but I would know that I need to use something to detect the player’s gamepasses and items. But it didn’t work well. I tried to search through Roblox DevForum for links to the gamepass searcher that works but I couldn’t find any; when I paste them in my browser, it detects classic items and not gamepasses. Here is my code and I appreciate the help, since this is actually confusing!
script that’s run legacy is client (script in workspace)
local HTTPService = game:GetService("HttpService")
local Market = game:GetService("MarketplaceService")
-- Cache results for 5 minutes
local cache = {}
local CACHE_DURATION = 300
-- REPLACE YOUR getPlayerAssets() WITH THIS:
local function getPlayerAssets(player)
-- Return cached data if available
if cache[player.UserId] and (os.time() - cache[player.UserId].timestamp < CACHE_DURATION) then
return cache[player.UserId].data
end
local items = {}
-- 1. Try official inventory API first
local success, inventory = pcall(function()
local response = HTTPService:GetAsync(
"https://inventory.roblox.com/v1/users/"..player.UserId.."/assets/collectibles?limit=100",
true -- Enable caching
)
return HTTPService:JSONDecode(response).data
end)
if success and inventory then
-- Add owned items
for _, item in ipairs(inventory) do
if item.isForSale then
table.insert(items, item.assetId)
end
end
else
-- 2. Fallback to roproxy catalog (only if inventory fails)
local success, catalog = pcall(function()
local response = HTTPService:GetAsync(
"https://catalog.roproxy.com/v1/search/items/details?Category=3&Limit=30&CreatorName="..player.Name,
true
)
return HTTPService:JSONDecode(response).data
end)
if success and catalog then
for _, item in ipairs(catalog) do
table.insert(items, item.id)
end
end
end
-- Cache results
cache[player.UserId] = {
data = items,
timestamp = os.time()
}
return items
end
script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
if plr and plr:FindFirstChild("Board") then
local board = script.Parent.Parent
if board and board:FindFirstChild("Values") and board.Values:FindFirstChild("Owner") then
local boardName = board.Name
local assets = getPlayerAssets(plr) -- Now uses the improved version
game.ReplicatedStorage.DonationButtons:FireServer(boardName, assets)
end
end
end)
serverscriptservice script
local Market = game:GetService("MarketplaceService")
local function CloneAssets(boardName, assets)
local board = game.Workspace.Boards:FindFirstChild(boardName)
if not board then return end
local frame = board.DonationBoard.SurfaceGui.DonationFrame
-- Clear existing buttons
for _, child in ipairs(frame:GetChildren()) do
if child:IsA("Frame") and child.Name ~= "Template" then
child:Destroy()
end
end
-- Create new buttons
for _, assetId in ipairs(assets) do
local success, data = pcall(function()
return Market:GetProductInfo(assetId)
end)
if success and data and data.IsForSale then
local button = script.Template:Clone()
button.Name = "Donate_"..assetId
button.PurchaseButton.Text = data.Name.."\n"..data.PriceInRobux
button.Visible = true
-- Store asset ID
local idValue = button:FindFirstChild("AssetId") or Instance.new("IntValue")
idValue.Name = "AssetId"
idValue.Value = assetId
idValue.Parent = button
button.Parent = frame
end
end
end
game.ReplicatedStorage.DonationButtons.OnServerEvent:Connect(function(plr, boardName, assets)
-- Validate board name is a string
if typeof(boardName) ~= "string" then
warn("Invalid board name received:", boardName)
return
end
-- Validate assets is a table
if typeof(assets) ~= "table" then
warn("Invalid assets format received")
return
end
-- Get board reference
local board = game.Workspace.Boards:FindFirstChild(boardName)
if not board then
warn("Board not found:", boardName)
return
end
-- Claim the board
plr:WaitForChild("Board").Value = boardName
board.Start.ProximityPrompt.Enabled = false
board.Values.Owner.Value = plr.Name
-- Update board UI
board.Player.SurfaceGui.Text.Text = plr.DisplayName.."'s Board"
board.Time.SurfaceGui.Text.Text = "Best Time: "..plr.leaderstats.BestTime.Value
board.Played.SurfaceGui.Text.Text = "Played: "..tostring(plr.leaderstats.Plays.Value)
board.Raised.SurfaceGui.Text.Text = "Raised: "..tostring(plr.Values.Raised.Value)
board.Donated.SurfaceGui.Text.Text = "Donated: "..tostring(plr.Values.Donated.Value)
board.Screen.BrickColor = BrickColor.new("Cyan")
board.Timer.SurfaceGui.Text.Text = "Click the Start button to play!"
-- Create donation buttons
CloneAssets(boardName, assets)
end)
Additionally, I feel like my script is wrong but I’m not sure.