I’m making a fling all product and a kill all product, and whenever i buy one, i cant buy the other. I’ve seen other people have this problem but I havent found a solution yet.
Scripts:
FlingAllServer
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Debris = game:GetService("Debris")
local PRODUCT_ID = 3463687403
MarketplaceService.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == PRODUCT_ID then
local buyer = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if buyer then
for _, player in ipairs(Players:GetPlayers()) do
if player ~= buyer then
local character = player.Character
if character then
local rootPart = character:FindFirstChild("HumanoidRootPart")
if rootPart then
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = Vector3.new(math.random(-100, 100), 100, math.random(-100, 100))
bodyVelocity.MaxForce = Vector3.new(1e5, 1e5, 1e5)
bodyVelocity.Parent = rootPart
Debris:AddItem(bodyVelocity, 0.5)
end
end
end
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
return Enum.ProductPurchaseDecision.NotProcessed
end
FlingAllClient
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local button = script.Parent
local PRODUCT_ID = 3463687403
button.MouseButton1Click:Connect(function()
local player = Players.LocalPlayer
if player then
MarketplaceService:PromptProductPurchase(player, PRODUCT_ID)
end
end)
the killall client side is the exact same as the flingall client except a different productid
KillAllServer
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local devProduct = 3463687532
MarketplaceService.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == devProduct then
local buyer = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if buyer then
for _, player in ipairs(Players:GetPlayers()) do
if player ~= buyer then
local character = player.Character
if character then
local hum = character:FindFirstChild("Humanoid")
if hum then
hum.Health = 0
end
end
end
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
return Enum.ProductPurch
You can only have 1 ProcessReceipt callback. Having 2 will just override the other.
Think of ProcessReceipt as a function that is a property of MarketplaceService. When you set it twice, which ever one is set after will be the one the game uses.
The reason why it is a callback (.Callback = function()) instead of a normal event (.Event:Connect(function()) is because you’re returning something, and if you have 2 functions returning 2 seperate things in the callback, how will it know what to do? This logic applies for RemoteFunctions as well.
I suggest you combine both of the functions, meaning they would have to be in the same script.
Following on what @7eoeb said, you need to combine both callback functions into one.
--// This is just a quick example I threw up.
local productFunctions = {
[3463687532] = function(receiptInfo) --// Fling All
local buyer = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if buyer then
for _, player in next, Players:GetPlayers() do
if player ~= buyer then
local character = player.Character
if character then
local rootPart = character:FindFirstChild("HumanoidRootPart")
if rootPart then
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = Vector3.new(math.random(-100, 100), 100, math.random(-100, 100))
bodyVelocity.MaxForce = Vector3.new(1e5, 1e5, 1e5)
bodyVelocity.Parent = rootPart
Debris:AddItem(bodyVelocity, 0.5)
end
end
end
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end,
[3463687403] = function(receiptInfo) --// Kill All.
local buyer = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if buyer then
for _, player in next, Players:GetPlayers() do
if player ~= buyer then
local character = player.Character
if character then
local hum = character:FindFirstChild("Humanoid")
if hum then
hum.Health = 0
end
end
end
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
}
MarketplaceService.ProcessReceipt = function(receiptInfo)
if productFunctions[receiptInfo.ProductId] ~= nil then
productFunctions[receiptInfo.ProductId]()
end
end
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productFunctions = {}
-- Example: product ID 123123 brings the user back to full health
productFunctions[123123] = function(receipt, player)
local character = player.Character
local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")
if humanoid then
humanoid.Health = humanoid.MaxHealth
-- Indicates a successful purchase
return true
end
end
-- Example: product ID 456456 awards 100 gold coins to the user
productFunctions[456456] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local gold = leaderstats and leaderstats:FindFirstChild("Gold")
if gold then
gold.Value += 100
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- Gets the handler function associated with the developer product ID and attempts to run it
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
-- The user has received their items
-- Returns "PurchaseGranted" to confirm the transaction
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
-- The user's items couldn't be awarded
-- Returns "NotProcessedYet" and tries again next time the user joins the experience
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Sets the callback
-- This can only be done once by one server-side script
MarketplaceService.ProcessReceipt = processReceipt
Great, just make sure to pass in the receiptInfo into the productFunction
MarketplaceService.ProcessReceipt = function(receiptInfo)
if productFunctions[receiptInfo.ProductId] ~= nil then
productFunctions[receiptInfo.ProductId](receiptInfo) -- <<< added 'receiptInfo'
end
end