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

Why are these developer products stacking?

For some reason, if you buy the product more than once, it will activate the reward multiple times. Why?

local MarketplaceService = game:GetService("MarketplaceService")
local character1, slotid = 42907443, 45098689
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

MarketplaceService.ProcessReceipt = function(receiptInfo) 
    local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
    if PurchaseHistory:GetAsync(playerProductKey) then
        return Enum.ProductPurchaseDecision.PurchaseGranted --We already granted it.
    end
    -- find the player based on the PlayerId in receiptInfo
    for i, player in ipairs(game.Players:GetPlayers()) do
        if player.userId == receiptInfo.PlayerId then
            -- check which product was purchased (required, otherwise you'll award the wrong items if you're using more than one developer product)
            if receiptInfo.ProductId == character1 then
                -- handle purchase. In this case we are healing the player.
                player.skins[tostring(player.PlayerGui.GUI.main_menu.character_select.buy_skins.skin.Value)].Value = player.skins[tostring(player.PlayerGui.GUI.main_menu.character_select.buy_skins.skin.Value)].Value+ 1
            elseif receiptInfo.ProductId == slotid then
                -- handle purchase. In this instance we're giving the player 100 extra gold. 
                player.data.slots.Value = player.data.slots.Value + 1
            end
        end 
    end
    -- record the transaction in a Data Store
    PurchaseHistory:SetAsync(playerProductKey, true)    
    -- tell ROBLOX that we have successfully handled the transaction (required)
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

1 answer

playerProductKey is never the same. Try using ProductId instead of PurchaseId

local playerProductKey = receiptInfo.PlayerId ..":".. receiptInfo.ProductId

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