Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

attempt to index nil with 'PlayerId'?

Hello I Have A Very Confusing Error In My Code Every Time I Tried To Fix It It Would Still Give Me The Error. Anyways This Is A LocalScript In StarterGui The Error Is At Line 6 Please Leave Any Suggestions Down Below.

local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

script.Parent.Purchase.MouseButton1Click:Connect(function()
	local function ProcessRecipt(RECINFO)
		local PLRREC = Players:GetPlayerByUserId(RECINFO.PlayerId)

		if not PLRREC then
			warn("ERR:USER_PURCHASED_PRODUCT_BUT_LEFT")
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
		if PLRREC then
			game.Players.LocalPlayer.leaderstats.gold.Value = game.Players.LocalPlayer.leaderstats.gold.Value+1
			warn("USER_PURCHASED_PRODUCT")
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end

	MPS:PromptProductPurchase(game.Players.LocalPlayer,1138765201,false,Enum.CurrencyType.Robux)	
	MPS.ProcessReceipt = ProcessRecipt()
end)

2 answers

You're calling the function on line 20. Not assigning it to ProcessReceipt.

3 comments

0

I Assigned It To ProcessReceipt And It Gave Me This Error .Can only register ProcessReceipt callback on server

0

Mhm, it means exactly what it does. All of the sufficient information is accessible with ProcessReceipt's parameters when processing on the Server, so don't fret about the transition. If you allowed the Client to manage DeveloperProducts, that would be incredibly detrimental.

0

Now that you know what bug was present in the code, I recommend migrating over to the Developer Wiki or YouTube to learn how to apply this properly.

When you call the function on line 20, you aren't passing any RECINFO parameter. So it errors because there is no PlayerId

Try something like:

MPS.ProcessReceipt = ProcessRecipt({PlayerId = 123456})

1 comment

0

ReceiptInfo is a dictionary containing the transaction data, it's given as an argument by ProcessReceipt.

This discussion is preserved as it was. New answers, comments, and votes are closed.