Recently, I made a script in my game where if the player purchases an item, a “Thanks for your purchase” UI comes up. It works fine except for one issue, the UI still comes up after I click cancel on the purchase UI that comes up when buying the dev product. How can I make it so that the UI only comes up when the player clicks the buy button
Here is the script currently:
local MPS = game:GetService("MarketplaceService")
MPS.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == 1151090217 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Levels.Value = player.leaderstats.Levels.Value + 20
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 1151090304 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Rebirths.Value = player.leaderstats.Rebirths.Value + 1
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif receiptInfo.ProductId == 1161224953 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 10
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
Explanations would be highly appreciated