I have an error while trying to get the player/UserID when a dev product is purchased, here is my script:
local productID = 1270692852 local MPS = game:GetService('MarketplaceService') local function processRecipet(RecieptInfo) local plr = game.Players:GetPlayerByUserId(RecieptInfo.PlayerId) if not plr then -- plr probably left. return Enum.ProductPurchaseDecision.NotProcessedYet end if RecieptInfo.PurchaseId == productID then if plr then local leaderstats = plr:WaitForChild('leaderstats') local Gems = leaderstats:WaitForChild('Gems') Gems.Value = Gems.Value + 50 end end return Enum.ProductPurchaseDecision.PurchaseGranted end -- call back MPS.ProcessReceipt = processRecipet()
The error is on this line:
local plr = game.Players:GetPlayerByUserId(RecieptInfo.PlayerId)
All of this is in a server script.
that's because you're calling the function instead of passing the function address to MPS.ProcessReceipt. removing the brackets in line 29 should fix it
MPS.ProcessReceipt = processRecipet
I believe it has something to do with this.
MPS.ProcessReceipt = processRecipet()
try using this instead
MPS.ProcessReceipt:Connect(processRecipet)