I am having problems with processReceipt

Hello! this is my first post and I am currently trying to create a button that prompts a purchase for a developer product. but once it’s bought it does not run the code. I’ve looked at some tutorials but to no help and I find the api-reference complicated to understand.

This is the local script located inside the button

local plr = game.Players.LocalPlayer
local ID = script.Parent.ID.Value

script.Parent.MouseButton1Click:Connect(function()
	game:GetService("MarketplaceService"):PromptProductPurchase(plr, ID)
end)



Script that handles the processReceipt located in ServerScriptService.

local MarketplaceService = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local ProductID1 = script.ID.Value


function processReceipt(receiptInfo)
	local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
	print("Player ID: "..receiptInfo.PlayerId) --It doesn't print.
	print("Product ID: "..receiptInfo.ProductId) --It doesn't print.
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	if receiptInfo.ProductId == ProductID1 then
		print("Purchase sucess.")
	end
	
	
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
	
end

MarketplaceService.ProcessReceipt = processReceipt

and yes the ID is correct.

Can you confirm that the server script is running correctly with a print and that there are not other scripts that may overwrite ProcessReceipt.

You local script looks good but I would advise against storing the if in value containers.

Oh it seems there were other scripts overwriting the ProcessReceipt, It was a donation board that my friend had inserted. and the reason why im storing the ids into values is to make it easy for my friend to edit since he lacks knowledge in coding and doesn’t want to mess anything up.

but thank you for your help.

1 Like

You could try something like that, personally this is my method for developer products, However I don’t see anything wrong with the script.

--Servicies--
local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
--Products--
local Products = {
	[1234567] = function(player)
		local stats = player:FindFirstChild("leaderstats")
		stats.Money.Value = stats.Money.Value + 10000
	end;
};
MarketPlaceService.ProcessReceipt = function(ReceiptInfo)
	for ID,Product in next, Products do
		if ReceiptInfo.ProductId == ID then
			local Player = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
			local Succes,Error = pcall(function()
				Products[ReceiptInfo.ProductId](Player)
			end)
			if not Succes then
				warn(Error)
				warn("Ready")
				return Enum.ProductPurchaseDecision.NotProcessedYet
			else
				warn("Failed")
				return Enum.ProductPurchaseDecision.PurchaseGranted
			end
		end
	end
end