Knowing the players country

IDK if I can do this but I found a game the detects what country are you.

3 Likes

It is possible to find a players region using LocalizationService. Here is an example.

local LS = game:GetService("LocalizationService")

game.Players.PlayerAdded:Connect(function(plr)
	local region = LS:GetCountryRegionForPlayerAsync(plr)
	print(plr.Name .."'s Region is: "..region)
end)

This will give you the abbreviated region a player is in (ex. CA = Canada), in terms of converting that into a country name, you could use a dictionary to convert it to the actual country name or something along the lines of that.

4 Likes

BTW, can I get the most country playing roblox so I can know what flag do I need to add?

2 Likes

Is there any privacy issues with making this visible to all players through a playertab?

1 Like

just saying this is just getting a player’s language

1 Like

@Oji0721 - You’d probably have to put that in the dictionary as well, sort of like resolving the region name for a flag.

@Awo_kein - To my knowledge, I don’t believe so. Assuming it’s a tool Roblox itself provides, they give developers full access to it and therefore it’s fair game however from a player perspective it might be nice to allow an option to toggle it, as I don’t think there is an option for a player to disable it in the settings tab of Roblox itself as it’s based on IP region data.

@p49p0 - I don’t believe so. Take a look at this: LocalizationService | Roblox Creator Documentation
" Returns a country/region code string according to player’s client IP geolocation. The supported country/region codes are as follows:"

2 Likes

Its most probably usa and canada and 4th ranking is India

For me, I would fire an event from the client to the server with the information of their connected region. Then store that in the player’s data.

RemoteEvent:Fire(... --[[their connected region]] )
-- This is just a table so we can access the players' data on every server script.
local RegionStore = DataStoreService:GetOrderedDataStore("Regions")
local PlayersData = require(...)

local function UpdateRegion(regionKey: string, number: number)
	RegionStore:UpdateAsync(regionKey, function(amount)
		if not amount then return 1 end

		if amount >= 0 then
			return amount + number
		end

		warn("The amount must not reach the negatives.")
		return 0
	end)
end

RemoteEvent.OnClientEvent:Connect(function(player, region: string)
	local oldRegion = PlayersData[player].Region

	-- This just checks if the region changed or the player is new.
	if not (oldRegion == region) then
		PlayersData[player].Region = region

		UpdateRegion(oldRegion)
		UpdateRegion(region)
	end
end)

Once the region has been added, on the ordered datastore, let’s say every 5 minutes we update/get the most playing country.

local function GetMostPlayingRegion(): String?
	local mostPlayingRegion = RegionStore:GetSortedAsync(false, 1)
	return mostPlayingRegion[1]
end

while true do
	print(GetMostPlayingRegion())
	task.wati(300)
end

You also have to make a debounce for the event handler because exploiters can just fire the event anytime and pass a random argument. Or check if the region is a valid region, idk. This is just an example, so I don’t really know if it works. I’ve never really tested it; I just made it in VS Code.

Edit: Now that I think about it, you can do it from the server; I’m dumb :yum:. So the remote event is really unnecessary; you can just remove that part and convert the event handler to a function.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.