I’m trying to make it so that when you buy a dev product it adds one to the Stage leaderboard.
local MarketplaceService = game:GetService("MarketplaceService")
function processReceipt(receiptInfo)
local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- script below controls what happens if bought
player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt
It does sort of what I asked. However, when you buy it twice it goes up by 2 and when you buy a third time it goes up by 3, and so on. How do I make it so it only adds 1 every time?
When someone successfully buys a product, save the PurchaseId to a data store with key being PurchaseId and the value being true (you can expand on this if you want a record of all sales). Also, whenever someone makes a purchase, check to make sure that PurchaseId is not saved to the data store. If PurchaseId is in the data store already, ignore the purchase, as its already been handled. This prevents the game from handling the same purchase twice.