Error occurred while processing product purchase

I am making a Robux Shop where you can buy the game currency (stars) with robux. I am not really good at scripting with the MarketplaceService, so I used the ProcessReceipt from the Developer Hub.

It worked perfectly a few days ago, but now it keeps giving me this error: “Error occurred while processing a product purchase”

Here is the script:

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

-- Data store for tracking purchases that were successfully processed

-- Table setup containing product IDs and functions for handling purchases
local productFunctions = {}
-- ProductId 123123 for a full heal
productFunctions[1215198990] = function(receipt, player)
	-- Logic/code for player buying a full heal (may vary)
	if player.Character and player.Character:FindFirstChild("Humanoid") then
		require(game.ReplicatedStorage.TweenModule):tween(player.stars, {Value = (player.stars.Value + 10000)})
		return true
	end
end
productFunctions[1215199705] = function(receipt, player)
	-- Logic/code for player buying a full heal (may vary)
	if player.Character and player.Character:FindFirstChild("Humanoid") then
		require(game.ReplicatedStorage.TweenModule):tween(player.stars, {Value = (player.stars.Value + 100000)})
		return true
	end
end
productFunctions[1215199924] = function(receipt, player)
	-- Logic/code for player buying a full heal (may vary)
	if player.Character and player.Character:FindFirstChild("Humanoid") then
		require(game.ReplicatedStorage.TweenModule):tween(player.stars, {Value = (player.stars.Value + 1000000)})
		return true
	end
end
--[[productFunctions[1215200472] = function(receipt, player)
	-- Logic/code for player buying a full heal (may vary)
	if player.Character and player.Character:FindFirstChild("Humanoid") then
		require(game.ReplicatedStorage.TweenModule):tween(player.stars, {Value = (player.stars.Value + 10000000)})
		return true
	end
end
]]
-- The core 'ProcessReceipt' callback function
local function processReceipt(receiptInfo)
	
	-- Determine if the product was already granted by checking the data store  
	local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
	local purchased = false
	
	-- Find the player who made the purchase in the server
	local player = 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
	
	-- Look up handler function from 'productFunctions' table above
	local handler = productFunctions[receiptInfo.ProductId]
	
	-- Call the handler function and catch any errors
	local success, result = pcall(handler, receiptInfo, player)
	if not success or not result then
		warn("Error occurred while processing a product purchase")
		print("\nProductId:", receiptInfo.ProductId)
		print("\nPlayer:", player)
		return Enum.ProductPurchaseDecision.NotProcessedYet
	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

Thanks,
doctorpepper126

Is the dev product under your game or from a third party game?

2 Likes

It is under my game yes (this message is here to make the post long enough)

Well, you really don’t need 70 line code to do something as simple as giving currency. Here’s my script that I did:

local MPS = game:GetService("MarketplaceService")
local ProductID = 1224007275 --change this to YOUR dev product. Not mine!
local Players = game:GetService("Players")
local function Receipt(ReceiptInfo)
	local BoughtProductId = ReceiptInfo.ProductId
	local Purchaser = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
	if not Purchaser then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if Purchaser and  BoughtProductId == ProductID then

		local Stars = Purchaser:WaitForChild("leaderstats"):WaitForChild("Stars")
		Stars.Value += 500



	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end
MPS.ProcessReceipt = Receipt

Also if you wanna see if this works then u can look here:
https://gyazo.com/91dbbd918ab6efe45063a1f1318f705f

I will try this out and let you know how it goes

Just found out that another script was interfering with this one. So it wasn’t anything in the script, but thanks for the shorter version.

Have a good rest of your day!

1 Like