Gamepass Search

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.

4 Likes

What is the purpose of your script? To see if a player owns a gamepass or to get a gamepass?

I have absolutely zero experience with working with scripts like this, but I believe that it won’t work if the user’s inventory visibility isn’t set to Everyone.
I believe Roblox has added a way for a game to access a user’s inventory (albeit with a message asking for permission to) as Catalog Avatar Creator has a way to see your inventory’s items. Maybe try looking into that.

That’s exactly what I’m trying to do.

Do you know what that thing is?

this? https://create.roblox.com/docs/reference/engine/classes/AvatarEditorService#PromptAllowInventoryReadAccess

something that can get all of the gamepasses
like this that wont work
https://www.roproxy.com/users/inventory/list-json?assetTypeId=34&nextPageCursor=&itemsPerPage=100&pageNumber=&sortOrder=Desc&userId=4211919501

if that thing you gave me is, can you put that in a script with a few lines?

Additionally:

Yeah that end point that lets you filter by assetType has been disabled. The swagger can be checked here.

Hopefully this other method works for you!

???


It looks like that wouldn’t work… my gamepasses arent showing up

Did you not read the other half of my message?

“You’re required to create an API key for all Open Cloud interactions; you can learn how to do that here. This will require you to add an x-api-key header to all of your GET requests, so study how either HttpService:GetAsync or HttpService:RequestAsync enables you to do that.”

1 Like