Gamepass Prompt Purchases Even When Player Has It

Recently, I made a script that prompt purchases a gamepass if the player does not have it and was intended to not run if the player owned the gamepass
However, even if the player owns the gamepass it still prompt purchases it, how can I make it that it doesn’t?

local function checkGamePassAndPrompt()
	-- Check if the player has the game pass
	local success, hasGamePass = pcall(function()
		return MarketplaceService:PlayerOwnsAsset(player, GAME_PASS_ID)
	end)

	if not hasGamePass then
		-- Player does not have the game pass, prompt them to purchase
		local success, message = pcall(function()
			MarketplaceService:PromptGamePassPurchase(player, GAME_PASS_ID)
		end)

	
		end
	end
1 Like

Use :UserOwnsGamePassAsync instead of :PlayerOwnsAsset. The documentation for Marketplace service even explicitly states to not use :PlayerOwnsAsset for gamepasses.

now it just doesnt prompt purchase at all

Not totally sure about this without testing but, it looks like your logic is off with the 2nd if.
Also I think PlayerOwnsAsset() is deprecated.

local function checkGamePassAndPrompt(player)
	local success, hasGamePass = pcall(function()
		return MarketplaceService:UserOwnsGamePassAsync(player.UserId, GAME_PASS_ID)
	end)

	if success and not hasGamePass then
		pcall(function()
			MarketplaceService:PromptGamePassPurchase(player, GAME_PASS_ID)
		end)
	end
end

You have to use :UserOwnsGamePassAsync() instead of playerownsasset

local function checkGamePassAndPrompt()
    local haspass
	-- Check if the player has the game pass
	local success, e = pcall(function()
		haspass = MarketplaceService:UserOwnsGamePassAsync(player, GAME_PASS_ID)
	end)
    if not success then warn(e) return end
    if not haspass then
		-- Player does not have the game pass, prompt them to purchase
		local success, e = pcall(function()
			MarketplaceService:PromptGamePassPurchase(player, GAME_PASS_ID)
		end)

	
		end
	end

Make sure you’re using the correct id for the gamepass. The gamepass id is the second set of numbers in the link to it


The first set (483182…) is the experience id and the second set (207600…) is the gamepass id