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

Devproduct handler get multiply help?

Asked by 2 years ago

I tried to mix 2 Devproducthandler but the rewards got multiply every purchase plss help

---//DEV RECEIPT\\---
--//MAIN
MarketplaceService.ProcessReceipt = function(receiptInfo)
    --//LOCALS
    --//PART 1
    local Success, Error = pcall(function()
    local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
    local amount = Products[receiptInfo.ProductId]

    player.leaderstats.Donated.Value = player.leaderstats.Donated.Value + amount
    player.playerstats.Dpoints.Value = player.playerstats.Dpoints.Value + amount
    end)

        --//PART 2
    local plrId = receiptInfo.PlayerId
    local purchasedId = receiptInfo.ProductId

    for i, pass in pairs(gamepasses) do

        local passId = pass[1]
        local productId = pass[2]

        if purchasedId == productId then

            local giftUserId = playersGifted[plrId]
            if giftUserId then
                playersGifted[plrId] = nil

                local success, err = pcall(function()
                    giftedData:SetAsync(giftUserId .. "-" .. passId, true)
                end)

                if success then
                    return Enum.ProductPurchaseDecision.PurchaseGranted
                else
                    return Enum.ProductPurchaseDecision.NotProcessedYet
                end
            else
                return Enum.ProductPurchaseDecision.NotProcessedYet
            end
        end
    end
end

2 answers

Log in to vote
1
Answered by 2 years ago

The problem here is your awarding the player twice. The first time you give the player their purchase, you should use an if statement for it.

0
Can you do it for me? I'm still new and not familiar with other things such as pcall AltairCelestia 47 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

I Rewrite the script and it shows no error. however it doesn't reward the player

MarketplaceService.ProcessReceipt = function(receiptInfo)
    --//LOCALS
    local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
    local amount = Products[receiptInfo.ProductId]

    local plrId = receiptInfo.PlayerId
    local purchasedId = receiptInfo.ProductId

    for i, pass in pairs(gamepasses) do

        local passId = pass[1]
        local productId = pass[2]
        local giftUserId = playersGifted[plrId]     

    local function ForSelf()
        local Success, Error = pcall(function()
        local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
        local amount = Products[receiptInfo.ProductId]

        player.leaderstats.Donated.Value += amount or 0
        player.playerstats.Dpoints.Value += amount or 0
        end)

    if Success then 
        return Enum.ProductPurchaseDecision.PurchaseGranted 
    else 
        warn(Error)
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end 
end

    local function ForSomeone()
        if giftUserId then
            playersGifted[plrId] = nil

        local success, err = pcall(function()
            giftedData:SetAsync(giftUserId .. "-" .. passId, true)
        end)

                if success then 
                    return Enum.ProductPurchaseDecision.PurchaseGranted
                else
                    return Enum.ProductPurchaseDecision.NotProcessedYet
                end 
            end




        if purchasedId == productId then
            ForSomeone()
        else
                ForSelf()
            end
        end
    end
end

Answer this question