Every time I purchase the product, the functions stack onto each other. After purchasing it once, it’ll call the function twice the next time I purchase it, and so on.
The script
local Market = game:GetService("MarketplaceService")
local StagesFolder = workspace:WaitForChild("Stages")
local Ids = require(game.ReplicatedStorage:WaitForChild("Ids"))
local productFunctions = {}
productFunctions["SkipStage"] = function(receipt, player)
local ls = player:FindFirstChild("leaderstats")
if ls then
local stage = ls:FindFirstChild("Stage")
if stage then
stage.Value = stage.Value + 1
player:LoadCharacter()
return true
end
end
end
local function processReceipt(receiptInfo)
if not receiptInfo.PlayerId then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local name = nil
for i,v in pairs(Ids.Products) do
if v and i then
if v == receiptInfo.ProductId then
name = i
end
end
end
local handler = productFunctions[name]
local success, result = pcall(function()
handler(receiptInfo, player)
end)
if not success or not result then
warn("Error occurred while processing a product purchase")
print("\nProductId:", receiptInfo.ProductId)
print("\nPlayer:", player)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
return Enum.ProductPurchaseDecision.PurchaseGranted
end
Market.ProcessReceipt = processReceipt