Gamepass prompt still firing after player has purchased it

Hello, Everybody

I have a store in my game where the player can buy gamepasses. Lets the player purchases a gamepass, but if he clicks again on the button he can purchase it again. That is the problem i am facing right now. A player can purchase 1 gamepass multiple times

local Script

local Players = game:GetService("Players")

local gamePassID = 63974938  

local purchase = script.Parent

local MarketplaceService = game:GetService("MarketplaceService")

local function promptPurchase()
	local player = Players.LocalPlayer
	local hasPass = false

	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
	end)

	if not success then
		warn("Error while checking if player has pass: " .. tostring(message))
		return
	end

	if hasPass then
		print("Gamepass is owned")
		-- Player already owns the game pass; tell them somehow
	else
		print("Gamepass not owned")
		-- Player does NOT own the game pass; prompt them to purchase
		MarketplaceService:PromptGamePassPurchase(player, gamePassID)
	end
end

purchase.Activated:Connect(promptPurchase)

The gamepass-owned print statement never runs even if the game pass actually is. I think the UserOwnsGamePassAsync built-in function might not work.

look into MarketPlaceService.PromptGamePassPurchaseFinished, might be able to help you

1 Like

You need to locally store the ownership state temporarily until the player leaves

The ownership API only periodically updates from the website, so its better to do what @2016Richman suggested

1 Like

I will try running that then I will check if the purchase was a success, if the purchase was successful then I will disable the button to purchase the pass. If the purchase was not successful I can print something indicating that the purchase was not successful. Anyways Ty for the idea.