and the top lines that should give 100 coins don’t work (see video). I have no idea how to fix this, by the way I didn’t get any error messages. I hope someone can solve this.
ProcessReceipt can only accept 1 function callback. It doesn’t work for 100 because another function overwrote it, put all the code in one ProcessReceipt callback function
Also, some advice
Put the local player line outside of the if statements since you would have duplicated code. Also make sure to check if the player is still in game via game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId), if it returns nil, the player left, so return Enum.ProductPurchaseDecision.NotProcessedYet
Use += value instead of = thing + value
If confused, I would recommend you send the code formatted correctly via 3 backticks (`) before and after your code
mps.ProcessReceipt = function(receiptInfo)
if (receiptInfo.ProductId == 1183433727) then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 100
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
mps.ProcessReceipt = function(receiptInfo)
if (receiptInfo.ProductId == 1183433728) then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 1000
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
MarketplaceService.ProcessReceipt = function(receiptInfo)
local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
--Player has left, do not say the purchase was successful
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if receiptInfo.ProductId == 1183433727 then
player.leaderstats.Coins.Value += 100
elseif receiptInfo.ProductId == 1183433728 then
player.leaderstats.Coins.Value += 1000
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
If you are not a scripter I would recommend you spend some time learning it so you can understand simple issues and how to fix them. In this case a trip to the Roblox api would’ve shown you the problem
MarketplaceService.ProcessReceipt is an index that defines a callback (function). You can change this callback but it can only have one function as it’s callback.
I would also be a nice lad and respect any bugs that might happen while setting the coins value, you can always return a non-processed receipt if so.
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
function MarketplaceService.ProcessReceipt(ReceiptObject)
local UserId = ReceiptObject.PlayerId
local LocalPlayer = Players:GetPlayerByUserId(UserId)
if rawequal(ReceiptObject.ProductId, 0) then
local success, response = pcall(function()
local Coins = LocalPlayer["leaderstats"].Coins
Coins.Value = Coins.Value + 1e2
end)
if success ~= true then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
elseif rawequal(ReceiptObject.ProductId, 0) then
local success, response = pcall(function()
local Coins = LocalPlayer["leaderstats"].Coins
Coins.Value = Coins.Value + 1e3
end)
if success ~= true then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end