Hello Devforum! Tonight while scripting a developer product script I was getting weird results from my script. Currently, when a user purchases one dev product the script acts as it is supposed to. However, when a person purchases 2 or more developer products it duplicates the first purchase and gives them the second purchase too. Is there any way I can remove the duplication? In this instance, after the two purchases, a user has 2-speed coils and 1 gravity coil when they should have one of each. Below is the script I have in serverScriptStorage. Thanks for reading!
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local speed = ReplicatedStorage:WaitForChild("speed")
local gravity = ReplicatedStorage:WaitForChild("gravity")
local productFunctions = {}
productFunctions[1232493084] = function(receipt, player) -- speed coil
local char = game.Workspace:FindFirstChild(player.Name)
local speedCoilClone = speed:Clone()
speedCoilClone.Name = "Speedcoil"
speedCoilClone.Parent = player.Backpack
end
productFunctions[1232495261] = function(receipt, player)
local char = game.Workspace:FindFirstChild(player.Name)
local gravityCoilClone = gravity:Clone()
gravityCoilClone.Name = "Gravitycoil"
gravityCoilClone.Parent = player.Backpack
end
local function processReceipt(receiptInfo)
print(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if player then
local handler = productFunctions[receiptInfo.ProductId]
local success, result = pcall(handler, receiptInfo, player)
print(result)
print(handler)
if success == false or not result then
warn("Error occurred while processing a product purchase")
print("\nProductId:", receiptInfo.ProductId)
print("\nPlayer:", player)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
-- Set callback
MarketplaceService.ProcessReceipt = processReceipt