I want to make a dev product that gives you cash after you purchase it.
The issue is that ProcessReceipt is not running. P.S. I have a donation board (used in most games with the dancing character) and I can’t remove it because there are people already on it that also uses ProcessReceipt. I don’t know how to detect it.
Code
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
local productFunctions = {}
productFunctions[1154827513] = function(receipt, player)
player.leaderstats.Cash.Value += 100
return true
end
productFunctions[1154827464] = function(receipt, player)
player.leaderstats.Cash.Value += 50
return true
end
productFunctions[1154827576] = function(receipt, player)
player.leaderstats.Cash.Value += 500
return true
end
productFunctions[1154827618] = function(receipt, player)
player.leaderstats.Cash.Value += 1250
return true
end
productFunctions[1154827693] = function(receipt, player)
player.leaderstats.Cash.Value += 4000
return true
end
productFunctions[1154827781] = function(receipt, player)
player.leaderstats.Cash.Value += 10000
return true
end
MarketplaceService.ProcessReceipt = function(receiptInfo)
print("Processed")
local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
local purchased = false
local success, errorMessage = pcall(function()
purchased = purchaseHistoryStore:GetAsync(playerProductKey)
end)
if success and purchased then
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif not success then
error("Data store error:" .. errorMessage)
end
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local handler = productFunctions[receiptInfo.ProductId]
local success, result = pcall(handler, receiptInfo, player)
if not success or not result then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local success, errorMessage = pcall(function()
purchaseHistoryStore:SetAsync(playerProductKey, true)
end)
if not success then
error("Cannot save purchase data: " .. errorMessage)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketPlaceService.ProcessReceipt = function(ReceiptInfo)
for ID,Product in next, productFunctions do
if ReceiptInfo.ProductId == ID then
local Player = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
local Success,Error = pcall(function()
productFunctions[ReceiptInfo.ProductId](Player)
end)
if not Success then
return Enum.ProductPurchaseDecision.NotProcessedYet
else
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
end
end
You are calling a function in a table, It should be:
local Tab = {
["TestFunction"] = function()
print("test")
end;
}
--Calling the function--
Tab["TestFunction"]() --Use () to call
You have already mentioned the issue that you have a donation board, ProcessReceipt can only be used by one script.
The first thing you should do is test the game, go to where the board is in the explorer, and copy the script that handles the listings, so you can add it with yours. Then afterwards, go to into the Products modulescript of the board and there should be a commented out property, uncomment it and it wont use the processReceipt it has.
There’s also some comments at the last bit that tell you what to do if you want to use your own processreceipt. If you’re still confused I could explain it a bit more simpler
I did that and changed the processReceipt function.
game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
local numberBought = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory"):IncrementAsync(playerProductKey, 1)
local ProductBought = game:GetService("DataStoreService"):GetDataStore("PurchaseHistoryCount"):IncrementAsync(receiptInfo.ProductId, 1)
local PlayerFound = false
for i, v in pairs (game.Players:GetChildren()) do
if v:IsA('Player') then
if v.userId == receiptInfo.PlayerId then
for _, p in pairs (Products.Products) do
if p.ProductId == receiptInfo.ProductId then
if v ~= nil then
PlayerFound = true
game:GetService("DataStoreService"):GetOrderedDataStore(GetData()):IncrementAsync(receiptInfo.PlayerId, p.ProductPrice)
end
end
end
end
end
end
print("Processed")
local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
local purchased = false
local success, errorMessage = pcall(function()
purchased = purchaseHistoryStore:GetAsync(playerProductKey)
end)
if success and purchased then
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif not success then
error("Data store error:" .. errorMessage)
end
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local handler = productFunctions[receiptInfo.ProductId]
local success, result = pcall(handler, receiptInfo, player)
if not success or not result then
warn("Error occurred while processing a product purchase")
print("\nProductId:", receiptInfo.ProductId)
print("\nPlayer:", player)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local success, errorMessage = pcall(function()
purchaseHistoryStore:SetAsync(playerProductKey, true)
end)
if not success then
error("Cannot save purchase data: " .. errorMessage)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
if PlayerFound ~= true then
return Enum.ProductPurchaseDecision.NotProcessedYet
else
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end