Attempt to index nil with 'PlayerId'

I keep getting an error saying "attempt to index nil with ‘PlayerId’
does anyone have this issue or know how to fix this?

local MarketplaceService = game:GetService("MarketplaceService")


local function processReceipt(receiptInfo)
	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
		if not player then
			-- player does not exist/ left game
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
	-- script below controls what happens if bought
	print(player.Name.." just bought ".. receiptInfo.PreoductId)
	player.leaderstats.Points.Value = player.leaderstats.Points.Value + 100
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
end


MarketplaceService.ProcessReceipt = processReceipt()
4 Likes

You are setting your processsreceipt’s return value as the value of MarketPlaceService.ProcessReceipt. You should set the function itself as its value. When you want to set a function as the value of something, don’t call that function (don’t put the parenthesis after it). You also have a typo in your function. You have written PreoductId where there should be ProductId.

MarketplaceService.ProcessReceipt = processReceipt
7 Likes