So, I’m trying to make a system where players can purchase additional money through a GUI. I understand this is insanely simple however I cannot see why it’s not working as it is originally from a tutorial.
ServerScript:
There are no errors in the output and the cash just simply isn’t given.
I’ve tested it on the client, in studio and everything and it isn’t working.
If someone could give a fix to this relatively simple problem (lol) it would be appreciated!
You shouldn’t need to test this by publishing it all the time, you can test this kind’ve thing on Roblox Studio. , what errors do you get in the console?
The only other thing I can think of is your receiptInfo.ProductID, I’m wondering if it’s case-sensitive and needs to be receiptInfo.ProductId instead… Try that.
Another thing I’ve considered too is, where is that script located? The ProcessReceipt callback function wants to be declared in a server script. Stick that script in a server script in ServerScriptService.
Can you confirm if the product ID you’re comparing receiptInfo.ProductId with is correct too? Is that product a part of a third-party game? I’m wondering if it’s to do with that if it is.
You should try keeping the base documentation code for it.
There was some typing errors in your script like UserId > PlayerId and ProductID > ProductId.
Also you need to do a pcall function to make sure the product was puchased, otherwise there can be a bug where people still receive the reward even when they are canceling the purchase.
local MarketplaceService = game:GetService("MarketplaceService")
local PlayerService = game:GetService("Players")
local ProductFunctions = {}
-- Product Functions
ProductFunctions[1654837831] = function(Receipt, Player)
local leaderstats = Player:FindFirstChild("leaderstats")
local Money = leaderstats and leaderstats:FindFirstChild("Money")
if Money then
Money.Value += 250
return true
end
end
-- Main Functions
MarketplaceService.ProcessReceipt = function(ReceiptInfo)
local UserId = ReceiptInfo.PlayerId
local ProductId = ReceiptInfo.ProductId
local Player = PlayerService:GetPlayerByUserId(UserId)
if Player then
local SelectedFunction = ProductFunctions[ProductId]
local Success, Result = pcall(SelectedFunction, ReceiptInfo, Player)
if Success then
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", ReceiptInfo, Result)
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end
Try this code, tested it on my Roblox Studio and it works fine:
game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == 1654837831 then
local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local leaderstats = player:FindFirstChild("leaderstats")
if not leaderstats then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local moneyVal = leaderstats:FindFirstChild("Money")
if not moneyVal then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
moneyVal.Value += 250
return Enum.ProductPurchaseDecision.PurchaseGranted
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end
It’s also important to note that you should be using PromptProductPurchase on the client. Like so: