Region that gives you the most robux revenue from your game

So i need a little small help, after the new dashboard audience update, I decided to create script using LocalizationService:GetCountryRegionForPlayerAsync() to achieve the region that gives devs mostly robux, but the main question is that even possible?
I’m not asking to write whole script, just suggestions what could I use to built such thing

2 Likes

Yes you make a table that contains all regions as keys and how much robux the region made as value. Then whenever a player buys a gamepass or a devproduct you check the player’s region and you increment it in the table by how much the gamepass costs

5 Likes

So let’s say the next code would work?:

local Players = game:GetService("Players")
local LocalizationService = game:GetService("LocalizationService")

local DATASTORE_NAME = "RegionRobuxMapping"

local regionRobuxMapping = {}
local dataStore = DataStoreService:GetDataStore(DATASTORE_NAME)
local success, savedRegionRobuxMapping = pcall(function()
    return dataStore:GetAsync("RegionRobuxMapping")
end)
if success and savedRegionRobuxMapping then
    regionRobuxMapping = savedRegionRobuxMapping
else
    warn("Failed to load RegionRobuxMapping from DataStore")
end

local function saveRegionRobuxMapping()
    local success, error = pcall(function()
        dataStore:SetAsync("RegionRobuxMapping", regionRobuxMapping)
    end)
    if not success then
        warn("Failed to save RegionRobuxMapping to DataStore:", error)
    end
end

local function incrementRobuxSpent(region, robuxAmount)
    regionRobuxMapping[region] = (regionRobuxMapping[region] or 0) + robuxAmount
end

local player = Players.LocalPlayer
if player then
    local region = LocalizationService:GetCountryRegionForPlayerAsync(player)
    local gamePassCost = 100
    incrementRobuxSpent(region, gamePassCost)
    saveRegionRobuxMapping()
else
    warn("Failed to find LocalPlayer")
end

Ikr script looks like nonsense because I just started thinking abt it

1 Like

yea the code looks fine, but obviously you should only call the increment function when a gamepass/devproduct is bought

okay i did include inc funct:

local Players = game:GetService("Players")
local LocalizationService = game:GetService("LocalizationService")

local DATASTORE_NAME = "RegionRobuxMapping"

local regionRobuxMapping = {}
local dataStore = DataStoreService:GetDataStore(DATASTORE_NAME)
local success, savedRegionRobuxMapping = pcall(function()
    return dataStore:GetAsync("RegionRobuxMapping")
end)
if success and savedRegionRobuxMapping then
    regionRobuxMapping = savedRegionRobuxMapping
else
    warn("Failed to load RegionRobuxMapping from DataStore")
end

local function saveRegionRobuxMapping()
    local success, error = pcall(function()
        dataStore:SetAsync("RegionRobuxMapping", regionRobuxMapping)
    end)
    if not success then
        warn("Failed to save RegionRobuxMapping to DataStore:", error)
    end
end

local function incrementRobuxSpent(region, robuxAmount)
    regionRobuxMapping[region] = (regionRobuxMapping[region] or 0) + robuxAmount
end

local player = Players.LocalPlayer
if player then
    local region = LocalizationService:GetCountryRegionForPlayerAsync(player)
    local gamePassCost = 100

    if player:HasGamePass(gamePassId) or player:HasDeveloperProduct(devProductId) then
        incrementRobuxSpent(region, gamePassCost)
        saveRegionRobuxMapping()
    end
else
    warn("Failed to find LocalPlayer")
end```
2 Likes

nevermind, it doesnt create any datastore atm

First of all this has to be in a server script can’t be local.
Second of all you’re trying to run a code that increments this value everytime a player joins. If the same player having the gamepass joins 10 times it will add 1000 robux to that region.
What you want to do is increment the value right after he makes the purchase

i guess you’re talking about the ss script that have rewrote 2 minutes ago:

local Players = game:GetService("Players")
local LocalizationService = game:GetService("LocalizationService")

local DATASTORE_NAME = "RegionRobuxMapping"

local dataStore = DataStoreService:GetDataStore(DATASTORE_NAME)
local regionRobuxMapping = {}

local function saveRegionRobuxMapping()
	local success, error = pcall(function()
		dataStore:SetAsync("RegionRobuxMapping", regionRobuxMapping)
	end)
	if not success then
		warn("Failed to save RegionRobuxMapping to DataStore:", error)
	end
end

local function incrementRobuxSpent(player, region, robuxAmount)
	regionRobuxMapping[region] = (regionRobuxMapping[region] or 0) + robuxAmount
	saveRegionRobuxMapping()
end

local function onPlayerAdded(player)
	local region = LocalizationService:GetCountryRegionForPlayerAsync(player)
	local gamePassId = "YOUR_GAMEPASS_ID_HERE" -- Replace with the actual game pass ID
	local devProductId = "YOUR_DEV_PRODUCT_ID_HERE" -- Replace with the actual dev product ID
	local gamePassCost = 100 -- Replace with the actual cost of the game pass or dev product

	player.CharacterAdded:Connect(function(character)
		if player:HasGamePass(gamePassId) or player:HasDeveloperProduct(devProductId) then
			incrementRobuxSpent(player, region, gamePassCost)
		end
	end)
end

Players.PlayerAdded:Connect(onPlayerAdded)```

see you still haven’t fixed the problem ok good its a server script but again this increments the value everytime the player spawns

yeah did rn, but still it doesnt create any datastore after buying gamepass

idk why should it create a datastore when a player purchases the gamepass but you haven’t even scripted anything for that.

local DataStoreService = game:GetService(“DataStoreService”)
local Players = game:GetService(“Players”)
local LocalizationService = game:GetService(“LocalizationService”)

local DATASTORE_NAME = “RegionRobuxMapping”

local dataStore = DataStoreService:GetDataStore(DATASTORE_NAME)
local regionRobuxMapping = {}

local function saveRegionRobuxMapping()
local success, error = pcall(function()
dataStore:SetAsync(“RegionRobuxMapping”, regionRobuxMapping)
end)
if not success then
warn(“Failed to save RegionRobuxMapping to DataStore:”, error)
end
end

local function incrementRobuxSpent(player, region, robuxAmount)
regionRobuxMapping[region] = (regionRobuxMapping[region] or 0) + robuxAmount
saveRegionRobuxMapping()
end

local function onCharacterAdded(character)
local player = character.Parent
local region = LocalizationService:GetCountryRegionForPlayerAsync(player)
local gamePassId = “YOUR_GAMEPASS_ID_HERE” – Replace with the actual game pass ID
local devProductId = “YOUR_DEV_PRODUCT_ID_HERE” – Replace with the actual dev product ID
local gamePassCost = 100 – Replace with the actual cost of the game pass or dev product

if player:HasGamePass(gamePassId) or player:HasDeveloperProduct(devProductId) then
	incrementRobuxSpent(player, region, gamePassCost)
end

end

Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(onCharacterAdded)
end)