Attempt to index nil with 'PlayerId'

  1. What do you want to achieve? I’m trying to make a ProcessReceipt function, for my Shop GUI, to handle purchases in a better way.

  2. What is the issue? As stated in the title, I’m getting an “Attempt to index nil with ‘PlayerId’” error.

  3. What solutions have you tried so far? I’ve looked on Roblox Developer Docs, but it didn’t help me.

This is the script:

local marketplaceService = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local LittleBagId = 1358219495
local SmallBoxId = 1358219815
local LargeBoxId = 1358220015
local BarrelId = 1358220122

local function processReceipt(receiptInfo)

	local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
	local leaderstats = player:WaitForChild("leaderstats")
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	if receiptInfo.ProductId == SmallBoxId then
		if player then
			local Gems = leaderstats["💎Gems"]
			Gems.Value += 4500
		end
	elseif receiptInfo.ProductId == LittleBagId then
		if player then
			local Gems = leaderstats["💎Gems"]
			Gems.Value += 3000
		end
	elseif receiptInfo.ProductId == LargeBoxId then
		if player then
			local Gems = leaderstats["💎Gems"]
			Gems.Value += 8000
		end
	elseif receiptInfo.ProductId == BarrelId then
		if player then
			local Gems = leaderstats["💎Gems"]	
			Gems.Value += 10000
		end
	end
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

marketplaceService.ProcessReceipt = processReceipt()

remove the pair of brackets at the end

1 Like

Which brackets exactly do you mean?

Oh I get what you meant now, thank you!

1 Like

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