local MarketService=game:GetService("MarketplaceService")
local ProductId=1504714840
local Player=game:GetService("Players")
local Coil=game.ReplicatedStorage.SpeedCoil
local function processReceipt(receiptInfo, player)
local players=Player:GetPlayerByUserId(receiptInfo.PlayerId)
if not players then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if receiptInfo.ProductId==ProductId then
if players then
local char=game.Workspace:FindFirstChild(players.Name)
Coil.Parent=char
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketService.ProcessReceipt=processReceipt
local MarketService=game:GetService("MarketplaceService")
local ProductId2=1504717907
local Players=game:GetService("Players")
local JumpCoil=game.ReplicatedStorage.JumpCoil
local function processReceipt2(receiptInfo2, player)
local player=Players:GetPlayerByUserId(receiptInfo2.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if receiptInfo2.ProductId==ProductId2 then
if player then
local char = game.Workspace:FindFirstChild(player.Name)
JumpCoil.Parent=char
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketService.ProcessReceipt=processReceipt2
I tried everything changing names of parameters but still not working. I expect it to run perfectly, two dev products. Two codes above are the two codes for my two dev products for my beginner game. I've read you can't use "MarketService.ProcessReceipt" twice but after looking into the dev api I don't understand why, I'm confused.
As you read already, the documentation says you should set the ProcessReceipt callback only once in a single Script.
If you're selling multiple products in your experience, this callback should handle receipts for all of them.
When you set the callback a second time, it overwrites the first callback. It does not add a second callback.
So try to join your two callbacks into one :
local MarketService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ProductHandlers = {
-- Coil
[1504714840] = function(player)
local Coil = ReplicatedStorage.SpeedCoil:Clone()
local char = player.Character or player.CharacterAdded:Wait()
Coil.Parent = char
end,
-- Jump Coil
[1504717907] = function(player)
local JumpCoil = ReplicatedStorage.JumpCoil:Clone()
local char = player.Character or player.CharacterAdded:Wait()
JumpCoil.Parent = char
end,
-- add more product handlers here ...
}
local function processReceipt(receiptInfo)
-- escape if the player has left before we grant the product
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- throw an error if we are selling a product we don't have a handler for
local handler = ProductHandlers[receiptInfo.ProductId]
if not handler then
error("No handler exists for " .. tostring(receiptInfo.ProductId))
end
-- do the thing that gives the product
handler(player)
-- mark this product as granted
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketService.ProcessReceipt = processReceipt