Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why am I getting an error in the PlayerId?

Asked by 3 years ago

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.

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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

If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.

Be sure to check out the Roblox API Documentation as well for additional reference.

0
I appreciate the help, but it still doesn't work. The prompt purchase works, its just that when you complete the purchase, you don't get the minigun. And I was a little puzzled with the RemoteFunction stuff, because I have very little experience with those. mymatevince1215 9 — 3y
0
Did it fix the error being printed or is a new one appearing? TaxesArentAwesome 514 — 3y
0
No error is appearing. But the mini gun isn't getting cloned into the players backpack mymatevince1215 9 — 3y
0
I've edited my response, check if it helps now. TaxesArentAwesome 514 — 3y
View all comments (4 more)
0
I'm not much of a good scripter myself so sorry bout that. Ima go see if it works now! I'll post if it doesn't work! mymatevince1215 9 — 3y
0
The elseif in elseif receiptInfo.PurchaseId == 1149873432 then gets a syntax error. Do you know why? mymatevince1215 9 — 3y
0
It just occured to me that `receiptInfo.PurchaseId` is a string and we are comparing it to a number. Put the numbers inside quotation marks. TaxesArentAwesome 514 — 3y
0
Sorry for the late response. Im going to try and see if it works. mymatevince1215 9 — 3y
Ad

Answer this question