ProcessReceipt code isn't firing

Hello, Developer community!
I recently ran into an issue regarding ProcessReceipt.
The issue is that my code doesn’t seem to be firing (evidenced by the valid sounds not playing, leader stats staying the same, and the donation message not being sent.)
I had done my research on how to fix this problem, but I couldn’t find a vital solution. My code changes haven’t worked either.
Would anyone be able to pinpoint the issue in the code?

MarketplaceService.ProcessReceipt = function(recieptInfo)
	local playerPurchasing = game.Players:GetPlayerByUserId(recieptInfo.PlayerId)
	if not playerPurchasing then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	local productId = recieptInfo.ProductId

	local productInfo = MarketplaceService:GetProductInfo(productId, Enum.InfoType.Product)

	if productInfo then
		if game.Players:GetPlayerByUserId(recieptInfo.PlayerId) then
			local leaderstats = playerPurchasing:FindFirstChild("leaderstats")
			if leaderstats then
				local money = leaderstats:FindFirstChild("Money")
				local donated = leaderstats:FindFirstChild("Donated")
				if donated and money then
					donated.Value += productInfo.PriceInRobux
					money.Value += productInfo.PriceInRobux * 3
					if game.Players:GetPlayerByUserId(productInfo.Creator.CreatorTargetId) then
						game.Players:GetPlayerByUserId(productInfo.Creator.CreatorTargetId).leaderstats.Raised.Value += productInfo.PriceInRobux
						game.Players:GetPlayerByUserId(productInfo.Creator.CreatorTargetId).leaderstats.money.Value += productInfo.PriceInRobux * 2
						local skyscraper = findSkyscraperByOwner(game.Players:GetPlayerByUserId(productInfo.Creator.CreatorTargetId).Name)
						wait(0.01)
						if skyscraper ~= nil then
							if productInfo.PriceInRobux <= 20 then
								game.Workspace[skyscraper].Area.SmallDonation:Play()
								game.Workspace[skyscraper].Area.DonationOverlay:Play()
							elseif productInfo.PriceInRobux >= 20 and productInfo.PriceInRobux <= 100 then
								game.Workspace[skyscraper].Area.DonationOverlay:Play()
								game.Workspace[skyscraper].Area.MidDonation:Play()
							elseif productInfo.PriceInRobux >= 100 and productInfo.PriceInRobux <= 1000 then
								game.Workspace[skyscraper].Area.DonationOverlay:Play()
								game.Workspace[skyscraper].Area.MidDonation:Play()
								game.Workspace[skyscraper].Area.Explode:Play()
							elseif productInfo.PriceInRobux >= 1000 and productInfo.PriceInRobux <= 10000 then
								game.Workspace[skyscraper].Area.SmallDonation:Play()
								game.Workspace[skyscraper].Area.DonationOverlay:Play()
								game.Workspace[skyscraper].Area.MidDonation:Play()
								game.Workspace[skyscraper].Area.Impact:Play()
								game.Workspace[skyscraper].Area.Explode:Play()
							elseif productInfo.PriceInRobux >= 10000 and productInfo.PriceInRobux <= 1000000 then
								game.Workspace[skyscraper].Area.DonationOverlay:Play()
								game.Workspace[skyscraper].Area.LargeDonation:Play()
								game.Workspace[skyscraper].Area.Explode:Play()
							elseif productInfo.PriceInRobux >= 1000000 then
								game.Workspace[skyscraper].Area.MassiveDonation:Play()
								game.Workspace[skyscraper].Area.LargeDonation:Play()
								game.Workspace[skyscraper].Area.Explode:Play()
							end
							remote:FireAllClients("[System] @" .. playerPurchasing.Name .. " donated \u{E002}" .. productInfo.PriceInRobux .. " to @" .. game.Players:GetPlayerByUserId(productInfo.Creator.CreatorTargetId).Name, Color3.fromRGB(0, 255, 8), Enum.Font.FredokaOne, Enum.FontSize.Size24)
						end
						local leaderstats2 = game.Players:GetPlayerByUserId(productInfo.Creator.CreatorTargetId):FindFirstChild("leaderstats")
						if leaderstats2 then
							local money2 = leaderstats2:FindFirstChild("Money")
							local raised = leaderstats2:FindFirstChild("Raised")
							if raised and money2 then
								raised.Value += productInfo.PriceInRobux
								money2.Value += productInfo.PriceInRobux * 2
							end
						end
					end
				end
			end
		end
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

I have looked into similar topics too, but they haven’t helped me with this issue.

2 Likes

Well, if you put a print in as the first thing under the function does that print it in the console? If so it’s a logic error in your function. If not it either is never hitting the function connection, or is getting overridden. There should only be one process receipt connection in the game so having another one somewhere else might affect this too.

1 Like

There’s only one, yes.
I could try to test out where the problem is via chat (because I need another person for this.)

1 Like

I have come to the conclusion that the MarketplaceService.ProcessReceipt isn’t firing at all. No logs have been printed at all. What do you suggest?

1 Like

Have you tried calling the function correctly? Is there actually a MarketplaceService module to handle ProcessReceipt? If not then you need to create a module (if you haven’t already)
and change it to another name, I don’t think you can declare functions in MarketplaceService.

1 Like

The strange thing was that I had done this before in another game, and it worked correctly.
The only thing was that I only had developer product purchases in that game, and not game passes.

1 Like

I think you still need to do that, it’s not even running for a reason and that is not being called properly. The game that uses this might break in the future if it suddenly interferes with the actual ProcessReceipt function.

1 Like

True, how would I go about fixing this problem?

1 Like

Create a module script then paste the function in the middle like this

local module = {} --presented in script

module.ProcessReceipt = function(receiptInfo)
-- ...code
return module -- presented in script

In the script that calls this function, first you need to require it to get access, then just call it when you need to.

local MarketModule = require(insert module location here) 

MarketModule.ProcessReceipt(info)

It should call the function properly now, I’m not sure if the function actually works

1 Like

Huh, it really was that simple? Nice, I’ll test it out.

2 Likes

Never mind, I switched over to MarketplaceService.PromptGamePassPurchaseFinished which made it work. Thanks for the help though!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.