My DevProduct isn't working correctly

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?

Help.

Hm i recommend explaining your problem with more details cuz then i cant help :confused: otherwise check lua learning.

Are you using a datastore? That might be a better solution than player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1

I’ve had this issue before!

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.

https://developer.roblox.com/en-us/api-reference/callback/MarketplaceService/ProcessReceipt

1 Like