I made a system where if you purchase a developer product, it updates an intvalue in a players leaderstats. When I purchase it the first time it works as expected, but when I try again it adds double the amount it’s supposed to.
Button Code:
local button = script.Parent
local id = 1527475121
local MPS = game:GetService("MarketplaceService")
local player = game:GetService("Players").LocalPlayer
local event = game.ReplicatedStorage.RemoteEvents.addCoins
local amount = 25
local deobunce = false
button.MouseButton1Click:Connect(function()
if not deobunce then
deobunce = true
MPS:PromptProductPurchase(player, id)
task.wait(1)
deobunce = false
end
end)
Handler Code:
local MPS = game:GetService("MarketplaceService")
local ids = {
1527474667,
1527474899,
1527475121
}
local event = game.ReplicatedStorage.bindableEvents.addCoins
local function processReceipt(receiptInfo)
local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local id
if player then
if receiptInfo.ProductId == ids[1] then
event:Fire(player, 25)
elseif receiptInfo.ProductId == ids[2] then
event:Fire(player, 50)
elseif receiptInfo.ProductId == ids[3] then
event:Fire(player, 100)
end
end
end
MPS.ProcessReceipt = processReceipt
Leaderstats Code:
event3.Event:Connect(function(player, amount)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + amount
end)