ProcessReceipt: ReceiptInfo is nil

I used a tutorial to create a ProccessReceipt function, but whenever I hit f5 to test it in studio, it tells me that ReceiptInfo.PlayerId is nil. I’m not sure how to fix this. Here is the script:

function processReceipt(ReceiptInfo)
	local plr = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
	if not plr then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	if plr and LoadedData then
		print("Bought A Donation")
		AmountDonated = AmountDonated + 10
		local Suc, Err = pcall(function()
			if ReceiptInfo.ProductId == SD then
				DonationODS:SetAsync(Player.UserId.."Donated",AmountDonated + 10)
			elseif ReceiptInfo.ProductId == MD then
				DonationODS:SetAsync(Player.UserId.."Donated",AmountDonated + 25)
			elseif ReceiptInfo.ProductId == BD then
				DonationODS:SetAsync(Player.UserId.."Donated",AmountDonated + 100)
			elseif ReceiptInfo.ProductId == HD then
				DonationODS:SetAsync(Player.UserId.."Donated",AmountDonated + 1000)
			end
		end)
		if Suc then
			print("Successfully Saved Donation")
		end
		if Err then
			print("There was an error saving your donation")
			warn(Err)
		end
	end
	print(AmountDonated)
	SaveData()
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

You aren’t assigning ProcessReceipt in MarketplaceService to this function. Whether you included that later or not is unclear so providing your whole code would be best. You can resolve this either by:

A) Adding MarketplaceService. and capitalising the P of ProcessReceipt.
B) Setting the value of ProcessReceipt to this function.

In code, they are the following:

function MarketplaceService.ProcessReceipt(ReceiptInfo)
end

local function processReceipt(ReceiptInfo)
end
MarketplaceService.ProcessReceipt = processReceipt

Personally, I’m not sure how you even got this code running without any of these in place.

3 Likes

I already had this in my script:

MarketPlaceService.ProcessReceipt = processReceipt()

Did you mean to put MarketPlaceService.ProcessReceipt = processReceipt
Because this:
MarketPlaceService.ProcessReceipt = processReceipt()
is calling the function not passing it as a callback.


btw, only_colbert already mentioned the both ways you can set MarketPlaceService.ProcessReceipt properly.

but sometimes simple mishaps happen

1 Like