Trouble using processreceipt on server

Hey, I’m trying to create a donation system and I am using processreceipt to make sure everything is processed properly and the player recieves their +100 robux on the donation leaderboard

I’m using the same structure as the roblox developer hub has described but it seems to, well not work.

Getting the error “Error occurred while processing a product purchase” which is a custom error message within the function

Server Script
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local DonationData = DataStoreService:GetDataStore(require(game:GetService("ReplicatedStorage").MocaexData).DonationData)
local DonationPrice = 100

local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")


local productFunctions = {}

productFunctions[1151407393] = function(receipt, player)
	-- Donation
	Donations = nil
	local success, errorMessage = pcall(function()
		Donations = DonationData:GetAsync(player.UserId.."Donations")
	end)
	
	if success then
		local dn = Donations + DonationPrice
		local success, errorMessage = pcall(function()
			purchaseHistoryStore:SetAsync(player.UserId.."Donations", dn)
		end)
	else
		game:GetService("ReplicatedStorage").Events.NotifyStaff("We had trouble processing "..player.Name.."'s Donation datastore request")
	end
	
end


local function processReceipt(receiptInfo)
	local player = "Hi"
	for _, Player in ipairs(game:GetService("Players"):GetChildren()) do
		if Player.UserId == receiptInfo.PlayerId then
			player = Player
		end
	end
	--print("ProductId:", receiptInfo.ProductId)
	print("Player:", player.Name)
	
	local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
	local purchased = false
	local success, errorMessage = pcall(function()
		purchased = purchaseHistoryStore:GetAsync(playerProductKey)
	end)

	if success and purchased then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif not success then
		error("Data store error:" .. errorMessage)
	end


	
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	local handler = productFunctions[receiptInfo.ProductId]

	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
	local success, errorMessage = pcall(function()
		purchaseHistoryStore:SetAsync(playerProductKey, true)
	end)
	if not success then
		error("Cannot save purchase data: " .. errorMessage)
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = processReceipt

This seems to be a problem with alot of people using this script from the developer hub. None of the soloutions posted on the devforum for this are working for me.

1 Like

I have the same problem, I tried that today but it didn’t work. :confused:

Hm, this is strange. It couldn’t be roblox is down as I bought a product from another game earlier.
I hope the developer hub gets updated with a simpler script.

1 Like

Nope the problem was the functions,

I had 2 problems

  1. forgot to return true at the end of the function

  2. and forgot to add :fireallclients at the end of my event (why?)

@CluelessAbd Try removing all the code apart from return true from the function and only having print(“test”), if that works, some of your code is broken in the function.

I used return true too and tried to print. ;-;

This is what worked for me, not sure what the is case for you, apologies I couldn’t help!