Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 7 years ago

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

Log in to vote
2
Answered by
cfiredog 274 Moderation Voter
7 years ago

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.

Ad

Answer this question