Hey I’m trying to add peoples Donation into a leaderstat and this script isn’t working after they purchase one of the buttons. If anybody can find the issue that would be amazing!
local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local donationIds = {
"1265665801",
"1265665829",
"1265665853",
"1265665881",
"1265665924",
}
MPS.ProcessReceipt = function(receiptInfo)
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if table.find(donationIds, receiptInfo.PurchaseId) then
local amountDonated = receiptInfo.CurrencySpent
player.leaderstats.Donated.Value += amountDonated
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
0 errors in the output aswell and it needs to add how much they just donated to the game into the leaderstats
local MPS = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
local donationIds = {
“1265665801”,
“1265665829”,
“1265665853”,
“1265665881”,
“1265665924”,
}
MPS.ProcessReceipt = function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if table.find(donationIds, receiptInfo.PurchaseId) then
local amountDonated = receiptInfo.CurrencySpent
player.leaderstats.Donated.Value += amountDonated
Hey man I appreciate the help but it still doesn’t work when I test in studio, do I need to test in roblox? But heres the script updated.
local MPS = game:GetService('MarketplaceService')
local Players = game:GetService('Players')
local donationIds = {
'1265665801',
'1265665829',
'1265665853',
'1265665881',
'1265665924'
}
MPS.ProcessReceipt = function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if table.find(donationIds, receiptInfo.PurchaseId) then
local amountDonated = receiptInfo.CurrencySpent
player.leaderstats.Donated.Value += amountDonated
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
There is no error in the code I provided. It looks like the code is setting up a custom ProcessReceipt function for the MarketplaceService , which is called when a player makes a purchase through the Roblox marketplace. The function checks if the purchase ID is in the donationIds table, and if it is, it adds the amount of currency spent on the purchase to the player’s Donated leaderboard statistic. If the purchase ID is not in the donationIds table or if the player cannot be found, the function returns Enum.ProductPurchaseDecision.NotProcessedYet .
local MPS = game:GetService('MarketplaceService')
local Players = game:GetService('Players')
local donationIds = {
1265665801,
1265665829,
1265665853,
1265665881,
1265665924
}
MPS.ProcessReceipt = function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if table.find(donationIds, receiptInfo.ProductId) then
local amountDonated = receiptInfo.CurrencySpent
player.leaderstats.Donated.Value += amountDonated
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
Oh it’s becuse Table.find was removed in like 2017, try this:
local MPS = game:GetService('MarketplaceService')
local Players = game:GetService('Players')
local donationIds = {
'1265665801',
'1265665829',
'1265665853',
'1265665881',
'1265665924'
}
MPS.ProcessReceipt = function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local donation = table.findValue(donationIds, receiptInfo.PurchaseId)
if donation then
local amountDonated = receiptInfo.CurrencySpent
player.leaderstats.Donated.Value += amountDonated
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
You can use the table.findIndex function to search for a value in a table and get its index, or you can use the table.findValue function to search for a value in a table and get the value itself.
I added a bunch of print statements with ur code and this is what I got when I donated 10 robux.
local MPS = game:GetService('MarketplaceService')
local Players = game:GetService('Players')
local donationIds = {
1265665801,
1265665829,
1265665853,
1265665881,
1265665924
}
MPS.ProcessReceipt = function(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
print("Not a play purchasing")
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if table.find(donationIds, receiptInfo.ProductId) then
print("found Donation id in table")
local amountDonated = receiptInfo.CurrencySpent
print(amountDonated)
player.leaderstats.Donated.Value += amountDonated
print("Added leaderstats")
return Enum.ProductPurchaseDecision.PurchaseGranted
else
print("error")
end
end