Hey developers,
I’m currently trying to make a global leaderboard to handle some stuff with donations and coins. The leaderboard is completed, I’m just adding a NumberValue into a “Statistics” folder inside of the player to track all donations, and to add up the donation amount value inside of the NumberValue.
I’m using DataStore2 to save all of this, and I’ve tried my code multiple times. Nothing seemed to work, so I went to the DS2 docs and got some of the Increment code there to see if that would work, but it still didn’t.
Keep in mind, I’m trying to add the developer product amount with :Increment().
My code:
-- avoidingfans
-- Services
local MarketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
-- Variables
local DonationNotificationRemote = ReplicatedStorage:WaitForChild("CORE_REMOTES"):FindFirstChild("GAME_REMOTES"):FindFirstChild("DonationNotification")
local DataStore2 = require(ServerStorage:WaitForChild("DataStore2"))
local ProductsTable = {
RobuxDonations = {
{1174031761, 50},
{1174031832, 500},
{1174031885, 2000},
{1174031937, 5000},
{1174032017, 10000},
{1174032073, 100000}
},
CashProducts = {
{1174327926, 50},
{1174327945, 100},
{1174327966, 250},
{1174327992, 1000}
}
}
-- Code
MarketPlaceService.ProcessReceipt = function(ReceiptInformation)
local Player = game.Players:GetPlayerByUserId(ReceiptInformation.PlayerId)
for i = 1, #ProductsTable.RobuxDonations do
local DeveloperProductId = ProductsTable.RobuxDonations[i][1]
local DeveloperProductAmount = ProductsTable.RobuxDonations[i][2]
if ReceiptInformation.ProductId == DeveloperProductId then
DonationNotificationRemote:FireAllClients(tostring(Player.Name), tonumber(DeveloperProductAmount))
local pointsStore = DataStore2("Donations", Player)
pointsStore:Increment(DeveloperProductAmount)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
for i = 1, #ProductsTable.CashProducts do
local DeveloperProductId = ProductsTable.CashProducts[i][1]
local DeveloperProductAmount = ProductsTable.CashProducts[i][2]
if ReceiptInformation.ProductId == DeveloperProductId then
local pointsStore = DataStore2("Coins", Player)
pointsStore:Increment(DeveloperProductAmount)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
end