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

Why is this adding more than it should?

Asked by 9 years ago

This keeps adding more than 10 like its suppose to... I've had this problem for many days and I can't find out why..

server script :

local DataStore = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local MarketService = game:GetService("MarketplaceService")
local productId = 23429504

function CompletePurchase(player)
    local stats = player:WaitForChild("leaderstats")
    local cash  = stats:WaitForChild("Cash")
local debounce = true    
cash.Value  = cash.Value + 10
end

MarketService.ProcessReceipt = function(receiptInfo) 
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            local ID,PROD = receiptInfo.PlayerID, receiptInfo.PurchaseId 

            if receiptInfo.ProductId == productId then
                CompletePurchase(player)
            end
        end
    end 

    local playerProductKey = "plr_" .. ID .. "_pur_" .. PROD
    DataStore:IncrementAsync(playerProductKey, 1) 

    return Enum.ProductPurchaseDecision.PurchaseGranted     
end



just incase you need this script : server script

local player = game.Players.LocalPlayer
local credits = game.StarterGui.MainGuis.Shop.Credits
game.Players.PlayerAdded:connect(function(player)
    local stats = Instance.new("Folder",player)
    stats.Name = 'leaderstats'
    local cash = Instance.new("IntValue",stats)
    cash.Name = "Cash"
    cash.Value = 10
    credits.Text = "Cash: "..player.leaderstats.Cash.Value..'$'
end)

promptpurchase script : local script

local buy = script.Parent
local productId = 23429504
enable=true
buy.MouseButton1Click:connect(function()
if enable==true then 
enable=false game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)
enable=true
end
end)
1
Try adding a debounce to the part that updates the cash. ZeroBits 142 — 9y
0
How can I do that? UnleashedGamers 257 — 9y
0
Basically, you would do it like this: jjwood1600 215 — 9y
0
Debounce = 0 and then if the product is bought check if the debounce is 0, if so then you can do what you need to do and then make the debounce 1. This will stop it from awarding multiple leaderstats. Hope that helped! jjwood1600 215 — 9y

1 answer

Log in to vote
-2
Answered by 9 years ago

Basic additions. Just add local debounce = false anywhere, make sure to put if debounce == false then debounce = true above where the problem is and at the end of the if statement, add debounce = false

EDIT: (P.S. Sorry, I didn't realize that somebody else posted that :/)

Ad

Answer this question