When purchasing, process receipt is called normally to start with. Then when purchased again, 2 process receipts are called. Then when purchased again, 3 are called etc. But this only happens when the function named SetQ has this code written below. I want to know what is causing it. Thanks for any help.
local function SetQ(PlrID, PlayerName, Parent, Name, BadgeID, Val)
local Value = Instance.new("StringValue")
Value.Parent = Parent
Value.Value = PlayerName
Value.Name = "Position"..Name
BS:AwardBadge(PlrID, BadgeID)
Val.Value += 1
if Val.Value > 2 then
local Max = Instance.new("ObjectValue")
local S = script.TimeUp:Clone()
Max.Name = PlayerName
Max.Value = PS[PlayerName]
if Parent == RolesFolder.SlaughtererQueue then
Max.Parent = RolesFolder.Q1_Consumed
S.Type.Value = "Q1"
else
Max.Parent = RolesFolder.Q2_Consumed
S.Type.Value = "Q2"
end
S.Parent = Max
S.Enabled = true
end
end
game:GetService("MarketplaceService").ProcessReceipt = function(ReceiptInfo)
pcall(function()
print("!")
local PlayerName = PS:GetPlayerByUserId(ReceiptInfo.PlayerId).Name
if ReceiptInfo.ProductId == 1234279250 then
SetQ(ReceiptInfo.PlayerId, PlayerName, RolesFolder.SheriffQueue, #RolesFolder.SheriffQueue:GetChildren() + 1, 2125917104, PS[PlayerName].Q2)
elseif ReceiptInfo.ProductId == 1234279275 then
SetQ(ReceiptInfo.PlayerId, PlayerName, RolesFolder.SlaughtererQueue, #RolesFolder.SlaughtererQueue:GetChildren() + 1, 2125917015, PS[PlayerName].Q1)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end)
end
.ProcessReceipt function is called every time the player joins or makes a new purchase for every time PurchaseGranted isn’t returned. Since you’re just making a pcall and not ever returning the result of the pcall to the enclosing function, you’re never actually returning .PurchaseGranted in the ProcessReceipt function.
So to make it work as expected, you need to remove the pcall and handle errors accordingly. You shouldn’t ever return .PurchaseGranted unless the purchase was truly granted.
I would assume this is because you’re creating a new function every time you call the .ProcessReceipt callback and it keeps listening to the function.
Try this instead:
function Receipt(ReceiptInfo)
pcall(function()
print("!")
local PlayerName = PS:GetPlayerByUserId(ReceiptInfo.PlayerId).Name
if ReceiptInfo.ProductId == 1234279250 then
SetQ(ReceiptInfo.PlayerId, PlayerName, RolesFolder.SheriffQueue, #RolesFolder.SheriffQueue:GetChildren() + 1, 2125917104, PS[PlayerName].Q2)
elseif ReceiptInfo.ProductId == 1234279275 then
SetQ(ReceiptInfo.PlayerId, PlayerName, RolesFolder.SlaughtererQueue, #RolesFolder.SlaughtererQueue:GetChildren() + 1, 2125917015, PS[PlayerName].Q1)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end)
end
game:GetService("MarketplaceService").ProcessReceipt = Receipt
Both of those are generally functionally the same, only one function “object” is created and gets assigned to marketplaceService.ProcessReceipt. The difference is that in your case you’re creating a named function and assigning it to marketplaceService.ProcessReceipt whereas in the OP, they’re creating a new function at the time .ProcessReceipt is assigned to. In either case, only one function gets created.
The only functional difference in this case is that you can access the function through the Receipt global.
If callbacks could be read from, you could get the function assigned to .ProcessReceipt through local receiptFunc = marketplaceService.ProcessReceipt