How to detect when a player cancels a premium purchase prompt?

I am writing a purchase service for my game, in which you can start a purchase by calling a function, it prompts the user to purchase, and then the function caller receives a promise which resolves later with the result of the purchase.

I have this up and running for gamepasses and developer products, but I am not sure how to go about prompting for premium purchases.

If the user closes the premium prompt, I want to resolve the promise with false, if they buy premium I want to resolve it with true. I can detect easily if they buy premium with the MembershipChanged event, but I am not sure how to detect when they close the purchase prompt so I can resolve the promise with false.

I realize there is a PromptPremiumPurchaseFinish event, but this event does not provide the player that closed the prompt (strangely, since most of these types of events do), making it impossible to trace back which player closed the prompt so I can resolve the right promise.

How can I go about this?

It actually does when you look at the API documentation!

https://developer.roblox.com/en-us/api-reference/function/MarketplaceService/PromptPremiumPurchase

I was surprised aswell when I saw that because the player parameter it says it provides will always be nil in game, not sure if it is an error in the documentation.

Oh hey thats weird, i tried it for myself and i also did get nil.

I think this might be an error in the documentation or roblox just straight up forgot to add the player to this event’s parameters.

Well if that’s the case it will be hard to pull this off. Best you can do is this check it on the client:

local MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.PromptPremiumPurchaseFinished:Connect(function()
	print(game.Players.LocalPlayer)
	
	-- Fire remote to the server telling it the player closed the window
end)

MarketplaceService:PromptPremiumPurchase(game.Players.LocalPlayer)

Or if you have a small/singleplayer game you can use this method:

local MarketplaceService = game:GetService("MarketplaceService")

local CurrentPlayerUsingPrompt

MarketplaceService.PromptPremiumPurchaseFinished:Connect(function()
	print(CurrentPlayerUsingPrompt)
	CurrentPlayerUsingPrompt = nil
end)

game.Players.PlayerAdded:Connect(function(plr)
	CurrentPlayerUsingPrompt = plr
	MarketplaceService:PromptPremiumPurchase(plr)
end)

But this is a really bad way of doing it, cause if 2 players uses the premium prompt at the same time it will basically break for the first player that opened it.

1 Like

I think for a temporary solution I’ll hook it up in the client, but I’ll post another topic as a bug report, hopefully Roblox can sort this out.

1 Like