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.
8 comments
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.
Did it fix the error being printed or is a new one appearing?
No error is appearing. But the mini gun isn't getting cloned into the players backpack
I've edited my response, check if it helps now.
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!
The elseif in elseif receiptInfo.PurchaseId == 1149873432 then gets a syntax error. Do you know why?
It just occured to me that
receiptInfo.PurchaseIdis a string and we are comparing it to a number. Put the numbers inside quotation marks.Sorry for the late response. Im going to try and see if it works.