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

Why is money giving script increasing the amount givin each time?

Asked by 6 years ago

This script is supposed to add 1000 gold to you're leaderstats when bought. It works except each time you buy it it gives you more. It is supposed to add 1000 only but every time you buy it it increase like this. 1st time: 1000 2nd: 2000 3rd:3000 4th:4000 etc. Why is it doing this.

-Full Script

--Script in BuyButton part
-- setup local variables
local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 92719865

-- define function that will be called when purchase finished
MarketplaceService.ProcessReceipt = function(receiptInfo) 

    -- find the player based on the PlayerId in receiptInfo
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then


            -- check which product was purchased
            if receiptInfo.ProductId == productId then

                -- handle purchase
                player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 1000
            end
        end
    end 

    -- record the transaction in a Data Store
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
    ds:IncrementAsync(playerProductKey, 1)  

    -- tell ROBLOX that we have successfully handled the transaction
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end
0
You IncrementAsync the key each time the event is called, you should only do this if the gold is added to the players stats. User#5423 17 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

try line 19 this might be the issue it seems like its adding 1000 to the value each time make it go from 1000 to 2000 and so on

 ~~~~~~~~~~~~~~~~~  player.leaderstats.Gold.Value = player.leaderstats.Gold.Value + 1000 ~~~~~~~~~~~~~~~~~  

Ad

Answer this question