Currently I want to create a way of tracking the amount of robux spent in my game. For example, tracking how much robux is spent and displayed on a leaderboard globally. I’ve seen many games have “Robux Leaderboards” or “Robux Spent”.
I’m very curious on the best way to do this.
Note: I want to track how much robux is spent on my game by gamepasses or dev products.
Roblox has no built-in methods for this. You just have to do it your self. Everytime the player buys something add the price of the pass to their robux spent value. Then make sure you save it to data store. This value would be just like making leaderstats btw
You can make an ordered data store for the amount of robux spent, and whenever a player has a gamepass, add to their data in the ordered data store. Be careful, because players can buy gamepasses outside of the game, in the store tab on the game’s page, so you’ll have to check if a player has a gamepass, instead of adding robux to their data whenever they buy it within the game.
For developer products, you’ll also have to be careful. You have to add to their data whenever the player buys a developer product, but data stores can fail, so in the ProccessReceipt function, make sure you return ProductPurchaseDecision.NotProcessedYet, so the game can run the function again until it succeeds.
local marketplaceService = game:GetService("MarketplaceService")
local dataStoreService = game:GetService("DataStoreService")
local dataStore = dataStoreService:GetOrderedDataStore("RobuxSpent") --This is the robux data store
marketplaceService.ProccessReceipt = function(info)
--Assume the price of the developer product is 50 robux
local success = pcall(function() --This adds 50 to the data store
dataStore:IncrementAsync(info.PlayerId, 50)
end)
--!! Make sure to return NotProcessedYet if it fails
if not success then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
--Give the perks the player bought to the player
--e.g. if they bought a product for 500 gems, give them 500 gems here
return Enum.ProductPurchaseDecision.PurchaseGranted
end