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()
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.
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.
-- 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.