This is the code: local function proccessedReceipt(receiptInfo) local player = players:GetPlayerByUserId(receiptInfo.PlayerId) if not player then return Enum.ProductPurchaseDecision.NotProcessedYet end if receiptInfo.PurchaseId == 1149873023 then if player then warn("a") local Mcopy = minigun1:Clone() local char = game.Workspace:FindFirstChild(player.Name) Mcopy.Parent = player.Backpack warn("b") end return Enum.ProductPurchaseDecision.PurchaseGranted end if receiptInfo.PurchaseId == 1149873432 then warn("c") local m2COPY = minigun2:Clone() local char = game.Workspace:FindFirstChild(player.Name) m2COPY.Parent = player.Backpack warn("d") end end
msSERVICE.ProcessReceipt = proccessedReceipt()
This is the error: 14:05:40.706 ServerScriptService.Script:9: attempt to index nil with 'PlayerId' - Server - Script:9
Any help? I'm stuck.
Howdy!
MarketplaceService.ProcessReceipt
is a callback, not an event. It's the same as having a RemoteFunction
and setting the function to fire. For something like that'd, you write something like:
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = MyFunction
That's the same thing here. Replace your last line in the script with what I have below.
msSERVICE.ProcessReceipt = proccessedReceipt
Edit:
So, I think the if-then statements had a misplaced end on it. Also, I'm confused why you're specifying a specific PurchaseId
. Did you mean to look for a specific UserId? Also, I think you should have a statement for when neither of the PurchaseId
's are what you're looking for. Regardless, I'm going to try to stick close to what you had originally. If you meant to look for UserId instead of a receipt number, I can help with that.
Try what I got on below and customize it to your liking. It'll check if the player is in-game and if their receipt number matches the correct receipt numbers listed. If the player is in-game and their receipt doesn't match any of the predetermined numbers, it'll warn in the output logs.
local function proccessedReceipt(receiptInfo) local player = players:GetPlayerByUserId(receiptInfo.PlayerId) if not player then return Enum.ProductPurchaseDecision.NotProcessedYet else if receiptInfo.PurchaseId == 1149873023 then warn("a") local Mcopy = minigun1:Clone() local char = game.Workspace:FindFirstChild(player.Name) Mcopy.Parent = player.Backpack warn("b") end return Enum.ProductPurchaseDecision.PurchaseGranted elseif receiptInfo.PurchaseId == 1149873432 then warn("c") local m2COPY = minigun2:Clone() local char = game.Workspace:FindFirstChild(player.Name) m2COPY.Parent = player.Backpack warn("d") else warn("This purchase has an incorrect receipt number.") end end end msSERVICE.ProcessReceipt = proccessedReceipt