Problem with Developer Products

Sometimes when the players purchase a developer product, their Robux is taken away, their purchase is completed but their benefit isn’t given. It works sometimes, so I’m not sure what it could be.

Here’s the Script handling the purchases.

local MarketplaceService = game:GetService("MarketplaceService")
MarketplaceService.ProcessReceipt = function(purchaseInfo)
	print("Purchase")
	local plr = game:GetService("Players"):GetPlayerByUserId(purchaseInfo.PlayerId)
    if plr then
	      print("Player found")
          local PurchaseCompleted = false
          if purchaseInfo.ProductId == **Product Id Here** then
                 print(plr.Name.." purchased a product")
                 -- Giving the stuff here
                 PurchaseCompleted = true
          end
          -- More Ifs-Thens like the one above
    if PurchaseCompleted then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
    return Enum.ProductPurchaseDecision.NotProcessedYet
    end
end

Here’s the localscript prompting the purchase:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local productID = **Product Id Here**
 
local function promptPurchase()
	local player = Players.LocalPlayer
	MarketplaceService:PromptProductPurchase(player, productID)
end

I’ve just tried to purchase a product in my game and nothing is printed in the console. How can I solve this?

1 Like

try changing PlayerId to UserId

Not working. Pretty sure that’s not the problem, since PlayerId is one of the 6 valid keys for the receiptInfo table.

Like Exarzz said i’d use UserId instead of PlayerId.

UserId is used more than anything else i think.

UserId is not an argument, purchasetInfo is a table. Check this to understand what I’m talking about: MarketplaceService | Documentation - Roblox Creator Hub

Oh yes i see. That’s my fault.

I looked back into my games product manager and see this:

local Market = game:getService("MarketplaceService")
local function CompletePurchase(PurchaseInfo)
	local plr = game:GetService("Players"):GetPlayerByUserId(PurchaseInfo.PlayerId)
	if PurchaseInfo.ProductId == IDHERE then
		v.Currency.Value = v.Currency.Value + v.Reward
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end
Market.ProcessReceipt = CompletePurchase

This is basically the same thing. I wonder what else could it be.

Try using the Script i last posted. replace the ID to yours and see.

It’s the same thing. Might be something else, I’ll investigate.

Alright. i’m sorry i couldn’t find a solution.
But i wish the best of luck to you. Debugging things is quite difficult however will definitely give you experience.

If nothing is being printed into the console, that means this isn’t the function defined to ProcessReceipt. If you have multiple scripts trying to set ProcessReceipt, only the most recent assignment will go through. You need to check for multiple cases of ProcessReceipt, including from external code you might be using, and consolidate it all together.

By the way: when it comes to a ProcessReceipt function, it’s better to actually return a ProductPurchaseDecision not at the end determined by a boolean but in the code itself. This way, your code isn’t unnecessarily running actions when a decision should already be made. You should be terminating operation right as something trips, either if the purchase succeeded or not.

In my cases, because I ensure that I always set things up properly, I always will assume that if the code does not trip any cases (no player, product with no handler so on), the purchase will be marked as complete and pass through. Success will always be the default return value and a queued purchase will always be the exceptive case.

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

local function processReceipt(receiptInfo)
    print("Processing purchase")
    local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then
        -- No player, cannot grant purchase. Step out of function and tell
        -- Roblox to queue the purchase for when ProcessReceipt is called again.
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    -- Consider using a dictionary instead to handle products. There are good
    -- code examples right on the Developer Hub.
    if purchaseInfo.ProductId == 0 then
        print("Purchase made by userId=" .. receiptInfo.PlayerId .. " for productId=" .. receiptInfo.ProductId)
        -- Give something out
    end

    -- Did not hit a NotProcessedYet return; assume all went well
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = processReceipt
2 Likes

Apparently I had an old script trying to set the ProcessReceipt, completely forgot about it. After I removed it I received the 2 purchases I made and didn’t trigger. I think this was the problem so thank you very much for your answer. I will also try to return without using the boolean variable to make sure everything runs smoothly.
Thank you!

1 Like