Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to check if the player pressed "Buy now" after prompting product purchase?

So basically I am made a developer product and gave it a function. But how to know if the player pressed "Buy now" after prompting product purchase? I wanna make a GUI appear and change a Data in a player's datastore when it happens but I don't know how to check if the player pressed "Buy now" instead of "cancel"

1 answer

✓ Accepted answer

You can check if a product prompt has ended through an event called PromptPurchaseFinished which is an event of MarketPlaceService.

This returns the player instance (of the player that finished purchasing), the ID of the product that was purchased (or wasn't), and lastly a bool value that indicates true (if purchased) or false (if not purchased).

local MarketplaceService = game:GetService("MarketplaceService")
local devProductIdEx = 12345

MarketplaceService.PromptPurchaseFinished:connect(function (player, assetId, wasPurchased)
	if assetId == devProductIdEx then -- check which product it was
		if wasPurchased then
			print("Product was successfully purchased")
		else
			print("Product purchase did not go through")
		end
	end
end)

Hope I helped, please let me know if you have any questions

1 comment

0

One question! Does PromptPurchaseFinished also work on LocalScript? By the way thank you giving me an answer!

This discussion is preserved as it was. New answers, comments, and votes are closed.