Why will my dev product code not work?

Hello,

So I am making a point thing where you can buy points by buying a dev product. I have done this but for some reason it says inside of the output that it is indexing nill with playerId. I am not sure why I am getting this error because it states inside the Receipt Info Table on the docs that playerId is one of them.

Serverscript Code:

local function processReceipt(receiptinfo)
	local plr = player:GetPlayerByUserId(receiptinfo.PlayerId)
	if not plr then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	if receiptinfo.ProductId == 1211236585 then
		PointsStoreage:SetAsync(plr.UserId, 5)
		plr.leaderstats.Points.Value = 5
	else if receiptinfo.ProductId == 1211236856 then
			PointsStoreage:SetAsync(plr.UserId, 10)
			plr.leaderstats.Points.Value = 10
		else if receiptinfo.ProductId == 1211237304 then
				PointsStoreage:SetAsync(plr.UserId, 50)
				plr.leaderstats.Points.Value = 50
			else if receiptinfo.ProductId == 1211237508 then
					PointsStoreage:SetAsync(plr.UserId, 100)
					plr.leaderstats.Points.Value = 100
				end
			end
		end
	end
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

MPS.ProcessReceipt = processReceipt()

Error:
image

It’s UserId not PlayerId. Change this line local plr = player:GetPlayerByUserId(receiptinfo.UserId)

1 Like

I still get the same issue.

image

Also it states in the docs that it is PlayerId.

Oh my bad, I believe it is PlayerId. The issue here could be your receiptinfo.

Am I doing this correctly then??

Yeah, try doing print(receiptinfo) at the top. If it’s nil then there is a problem.

Yea it comes out as nil. For some reason it is also runing when the game starts not when someone buys the product.

I would just recommend doing this:

MPS.ProcessReceipt = function(receiptinfo)
   -- Put the code from the function here.
end)

It does not run the code if I do that

Do you have button that when pressed it will popup?

Basically how it works is when u click one of them buttons it will make the product prompt purchase come up (done via a client script) and then I want it so if they buy it it will give the the points.

image

May I see the client script please?

script.Parent.PointsUI.FivePoints.TextButton.MouseButton1Click:Connect(function()

MPS:PromptProductPurchase(game.Players.LocalPlayer, 1211236585)

end)

(just one of the things)

When you press the button does it 100% work? Add a print in the client script above the Prompt Line and check if that prints anything in the output.

I know it works cuz it comes up with the prompt purchase lol. If it did not work I swear that would not come up.

Wait so what doesn’t work exactly, just the prompt purchase. To me it seems like everything works. :joy:

So the prompt purchase comes up but when I click on the buy button it says I brought it but does not run the code in the server script to give me the points.

I believe this is the issue in your original post

MPS.ProcessReceipt = processReceipt()

You are passing the function with no inputs. Replace it with this instead.

MPS.ProcessReceipt = processReceipt

And it should pass the receiptinfo attribute to your function.

-- Client Side
local MPS = game:GetService("MarketPlaceService")

script.Parent.PointsUI.FivePoints.TextButton.MouseButton1Click:Connect(function()
   MPS:PromptProductPurchase(game.Players.LocalPlayer, 1211236585)
end)

-- Server Side
local MPS = game:GetService("MarketPlaceService")

MPS.ProcessReceipt = function(recieptinfo)
   local Player = player:GetPlayerByUserId(receiptinfo.PlayerId)

   if not Player then
       return Enum.ProductPurchaseDecision.NotProcessedYet
   end
	
   if receiptinfo.ProductId == 1211236585 then
      -- Do whatever here
   elseif

   end

   return Enum.ProductPurchaseDecision.PurchaseGranted
end)
-- Add a bunch of prints to see what actually gets printed.

Oh right, I thought as much but I wasn’t sure how you would pass it through which is why I asked him to do MPS.ProcessReceipt = function() but I appreciate that, I didn’t know that.

1 Like