Help with ProcessReciept issue

Today i would like to script a dev product but get a error
My code

	local productfunction = {}
	productfunction[2147694924] = function(receipt, player)
		local level:IntValue = player.AdditionalData.BattlePassLevel
		level.Value += 1
		game.ReplicatedStorage.Remotes.GiveReward:Fire(player,level.Value)
		game.ReplicatedStorage.Remotes.LevelChanged:FireClient(player,level.Value)
		return true
	end
	local function processReceipt(receiptInfo)
		local userID = receiptInfo.PlayerId
		local productId = receiptInfo.ProductId
		
		local plr = game.Players:GetPlayerByUserId(userID)
		if plr then
			local handler = productfunction[productId]
			
			local success, result = pcall(handler,receiptInfo,plr)
			if success then
				return Enum.ProductPurchaseDecision.PurchaseGranted
			else
				print("Failed to purchse" .. receiptInfo)
			end
		end
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	 
	MarketPlace.ProcessReceipt = processReceipt()

error

  20:48:39.941  ServerScriptService.BattlePass:65: attempt to index nil with 'PlayerId'  -  Server - BattlePass:65
1 Like

By including the parenthesis, you’re not assigning the function itself, you’re running it and assigning it’s return value. Hence, when it’s run, you get that error. Simply change the line to this:
MarketPlace.ProcessReceipt = processReceipt

2 Likes

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