MarketplaceService help needed ASAP

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.

Any help would be greatly appreciated!

1 Like

You can only have a single ProcessReceipt callback active at a time, which is stated on the documentation.

1 Like

If you require multiple scripts to process receipts, you can make a ModuleScript to allow yourself to “bind” multiple functions to ProcessReceipt.

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

return function(callback) -- The ModuleScript output
    table.insert(processors, callback) -- Simply add the function to the list
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
    -- If this function is not responsible for the product,
    -- don't return anything so the ModuleScript will pass on to the other functions!
1 Like