I have a button that when clicked, prompts the purchas of a dev product. Strangely the receiptInfo doesn’t seem to be passed to the function.
Here’s the error given: ... attempt to index nil with 'PlayerId'
Server Script:
local MarketPlace = game:GetService('MarketplaceService')
local Players = game:GetService('Players')
local productID = 1094898392
local ServerStorage = game:GetService('ServerStorage')
local sword = ServerStorage:WaitForChild('ClassicSword')
local function processReceipt(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- player left game
-- if they come back, this will be called again
return Enum.ProductPurchaseDecision.NotProcessedYet
else
if receiptInfo.ProductId == productID then
local swordClone = sword:Clone()
swordClone.Parent = player.Character
print(player.Name .. ' just bought a nice ol\' sword!')
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
-- Set Callback
MarketPlace.ProcessReceipt = processReceipt()
Localscript
local MarketPlace = game:GetService('MarketplaceService')
local Players = game:GetService('Players')
local productID = 1094898392
local player = Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function ()
MarketPlace:PromptProductPurchase(player, productID)
end)