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

[RESOLVED]How to stop my developer products from processing multiple times?

Asked by 8 years ago

Here is my developer product code:

local fiveId = 30947986
local tenId = 30948013
local twentyfiveId = 30948036
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            local cash = player.leaderstats.Cash
            if receiptInfo.ProductId == fiveId then
                cash.Value = cash.Value + 5000
                print(player.Name .. " purchased 5K.")
            elseif receiptInfo.ProductId == tenId then
                cash.Value = cash.Value + 10000
                print(player.Name .. " purchased 10K.")
            elseif receiptInfo.ProductId == twentyfiveId then
                cash.Value = cash.Value + 25000
                print(player.Name .. " purchased 25K.")
            end     
        end
    end
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
    PurchaseHistory:IncrementAsync(playerProductKey, 1)
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

Right now when I buy a product it runs through the script multiple times. Buying the 5K might add 5000 to my cash one time but then buy it again and it might add 15000 or 20000.

I bought the 10k one and the output was: Player purchased 10K. Player purchased 10K. Player purchased 10K. Player purchased 10K. Player purchased 10K. Player purchased 25K.

0
Add a debounce, cause it's running it more than once sometimes. NinjoOnline 1146 — 8y
0
Is there anything in the output? TheDeadlyPanther 2460 — 8y
0
And how can they add random amounts of cash? It's impossible, it can only add any one of the amounts you defined. TheDeadlyPanther 2460 — 8y
0
@NinjoOnline @TheDeadlyPanther It is running multiple times, I added a print line in there and it's repeated over and over in the output when it runs. I tried adding a debounce but the script just stopped working. FierceByte 25 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

Looks like it's working now, all I changed was: local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId to local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId since it was too long.

Ad

Answer this question