Getting User's Country

I was recently playing a game and found that they had my exact country, how would I achieve this myself? I tried using Localization:GetCountryRegionForPlayerAsync() but that returns GB. The game I played had something a lot more specific.

1 Like

You can use a third party website for this. I will link the one I use for you. http://ip-api.com/json/

2 Likes

How exactly would I implement this into a LocalScript to get the user’s country?

1 Like

Oh for the user, you should have specified. The game you were playing probably was showing server statistics not the location of the player. This would be a security issue if you were able to do this I believe. To get the users country, you answered your own question in your OP.

2 Likes

Ah, do you know any ways I can convert the user’s region (e.g. GB) to a full name (e.g. Great Britain)?

As far as I am aware you have to use an if statement do to that.

local Country = ""
if bool and code == "GB" then
	Country = "Great Britain"
end
1 Like

Nono, I want to automatically convert the user’s country/region. For them it might not return GB.

I am aware of that but I do not think you can.

1 Like

I’ll make a new post. Maybe someone made an open-sourced module for it.

Let me know if you find anything, if not I will make it myself at some point soon.

1 Like

Hello there, LocalizationService is used to get player’s country.

Here is a sample code, which is used in a local script:

local LocalizationService = game:GetService("LocalizationService")
local player = game.Players.LocalPlayer

local result, code = pcall(function()
	return LocalizationService:GetCountryRegionForPlayerAsync(player)
end)

if result and code == "NO" then
	print("Hello, Norway")
else
	print("GetCountryRegionForPlayerAsync failed: " .. code)
end
1 Like

Change the code to your country Region, and note that this does not work in Studio, meaning you will have to publish in order to see your country by pressing F9, in the developer console.

1 Like
8 Likes

Thank you, however I wanted to ask, why do you need this anyway? The player would already know which country they are in?

1 Like

Just wanted to add something cool to F9 when my module loads into the game.

I tried on a few online tools, and it looks like it passes the China Firewall. Might be useful to make a game playable in China.

oh god thank you!

Just the thing is I was researching that for my own game and no one seems to have an answer, this actually helps a lot

Where does this script go? Like in a text gui??