What to do when game failed to handle purchase

Hello Developers,

I would like to ask question, let’s say someone buy’s something for Robux from one of my developer products, and the game couldn’t find the item that Player suppose to get, what I should return to Roblox to know that the game failed to handle purchase and to not charge the Player for the product? Or if this doesn’t exist, then would be fair enough to give player an message that purchase failed but he got (for example 1,500 coins)?

I am a bit new to developer products

So far this is my script:

local MarketplaceService = game:GetService("MarketplaceService")
 
local function processReceipt(receiptInfo)
	
	-- Find the player who made the purchase in the server
	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		-- The player probably left the game
		-- If they come back, the callback will be called again
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	-- Output what product they bought
	print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)
	
	if receiptInfo.ProductId == 514339861 then
		for _,car in pairs(game.Workspace.VehiclesFolder:GetChildren()) do
			if car:FindFirstChild("Configuration") then
				if car.Configuration:FindFirstChild("BoostFuel") then
					car.Configuration.BoostFuel.Value = 100
				end
			end
		end
		print("All cars boost fuel has been filled up")
	end
	
	-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
	return Enum.ProductPurchaseDecision.PurchaseGranted
end
 
-- Set the callback (this can only be done once by one script on the server!)
MarketplaceService.ProcessReceipt = processReceipt

Or everything is fine what I have done so far?

1 Like

Consult documentation first before posting threads. This question is answered for you on the page of ProcessReceipt.

If your game fails to handle a purchase in any capacity, you are expected to return Enum.ProductPurchaseDecision.NotProcessedYet in ProcessReceipt. You’ve done so if the player does not exist in the game, now you have to account for the loop you have and return NotProcessedYet if none of that does anything for the player.

2 Likes