So right here i just post the whole script i made, but the explications are below the script →
local Price = {300, 750, 2000, 10000}
local ids = {1570289776, 1570289898, 1570290492, 1570290617}
productFunctions = function(receipt, plr)
local Tout = plr:FindFirstChild("Tout")
local Coins = Tout and Tout:FindFirstChild("Coins")
if Coins then
local amount = Price[table.find(ids, receipt['ProductId'])]
Coins.Value += amount
rs.ClientEvents.DevProductsOk:FireClient(plr, amount)
coroutine.wrap(save)(plr, nil, true)
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
local handler = productFunctions
local success, result = pcall(handler, receiptInfo, player)
if success then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end
MarketService.ProcessReceipt = processReceipt
So the script above use the ProcessReceipt function of the Roblox documentation official, the problem is just here →
local success, result = pcall(handler, receiptInfo, player)
if success then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
With theses lines of code, even if the function handler don’t return true it’ll still return Enum.ProductPurchaseDecision.PurchaseGranted while it shouldn’t as something wrong happened with the handler → the player loss his robux.
To fix this it is very simple, you just need to add result in the condition →
local success, result = pcall(handler, receiptInfo, player)
if success and result then
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
In this case if it doesn’t return true, it’ll return Enum.ProductPurchaseDecision.NotProcessedYet and you’re safe with your player.
I think it could be fixed in the documentation or i’m not sure if this “error” is intented…