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

How to get script to wait for a purchase to be finished?

Let's say I prompted a purchase in my game, and when the purchase is finished, whether they bought it or not, I want the gui to disappear. How would I do that?

1 answer

To achieve this, you can use the PromptPurchaseFinished event of the MarketplaceService.

Example:

local MarketplaceService = game:GetService("MarketplaceService")
 
MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, isPurchased)
	if isPurchased then
		print(player.Name .. " bought an item with AssetID: " .. assetId)
	else
		print(player.Name .. " didn't buy an item with AssetID: " .. assetId)
	end
end)

If you want the GUI to disappear regardless of whether a purchase was made or not, then you can get rid of the if-statements and just set the GUI Enabled property to false in the function.

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