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)

4 comments
Try adding a debounce to the part that updates the cash.
How can I do that?
Basically, you would do it like this:
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!