I am having an issue in which multiple scripts are defining the marketplace service, and overriding each other. one script is for purchasing a pet egg which costs robux (it is a dev product), and the other script is for giving players money when the purchase coins in the shop.
When i attempt to purchase the coins in the shop, it will give me the coins that i purchased, but the pet egg wont work. it also happens the other way around.
If you require multiple scripts to process receipts, you can make a ModuleScript to allow yourself to “bind” multiple functions to ProcessReceipt.
ModuleScript
local ms = game:GetService("MarketplaceService")
local processors = {} -- An array of registered functions
function ms.ProcessReceipt(receipt) -- The actual ProcessReceipt, only used in this ModuleScript
for i,p in pairs(processors) do -- Loop through the functions
local result = p(receipt) -- Run the function with the receipt info
if result then return result end
-- Return function result if there is any, this will also prevent other functions from running
end
end
return function(callback) -- The ModuleScript output
table.insert(processors, callback) -- Simply add the function to the list
end
Any script processing product purchases
local registerProcessReceipt = require(<path.To.ModuleScript>) -- The function returned by the ModuleScript
registerProcessReceipt(function(receipt) -- Example function
if receipt.ProductId == 123 then -- Check if this function is responsible for this product
-- >>> Processing the product goes here <<<
return Enum.ProductPurchaseDecision.PurchaseGranted
-- ModuleScript will return this decision and not run any other functions.
-- Use NotProcessedYet if applicable
end
-- If this function is not responsible for the product,
-- don't return anything so the ModuleScript will pass on to the other functions!
end)