How to get server region?

Im trying to get the region the server is located in but httpservice wont work, ive tried many different json website thingies but none of them work when in the actual game only in studio. Is there a solution that doesnt requier http service?

Please always check before your post if a similar one exists. You can find the solution here:

“Im trying to get the region the server is located in but httpservice wont work” Please always check before sending me to another post

local function getServerData()
	local suc, getIp = pcall(function()
		return HttpService:GetAsync("https://ifconfig.io/all.json")
	end)

	local ipData = {}
	local serverIP

	if getIp then
		ipData = HttpService:JSONDecode(getIp)
		serverIP = ipData["ip"]
	end

	local success, serverData = pcall(function()
		return HttpService:GetAsync("https://ipapi.co/"..serverIP.."/json/") 
		-- if you plug in the above URL with the IP, you can get the actual
		-- raw JSON that includes a list of keys that you can use.
	end)


	if serverData then
		serverData = HttpService:JSONDecode(serverData) -- this returns things like
													 -- {
													-- 	region = "Virginia"
													--	country_code = "US"
													-- }
	end
 
	-- do something with this data, i.e.
	
	--print(serverdata[region] .. " " .. serverData[country_code]) may print "Toronto, CA"

end

Edit: additional clarification on serverData
https://ipapi.co/YOUR-IP/json/ returns a JSON file that can be decoded and turned into a dictionary. If you plug your IP or the server IP into the actual URL on the browser, you can get something like this:


As the code above, once you decode it, you can just get the info as if it were a simple dictionary

Edit2: You will need HTTP service and API service to get anything about the server information. Otherwise, LocalizationService would be your second best option, although it only tells you what country the player is located in. You can, as @doomguy2164 said, get the first player’s locale; though the true first player won’t always be consistent.

5 Likes

If OP wanted an AI slop response, they wouldn’t have asked here.
Plus, it doesn’t even exist.
image
ChatGPT can make mistakes. Check important info.

the prompt was ‘generate me a fake response about roblox’s region service’ :sob:

1 Like

Okay I fell for it. Well played.

1 Like

Whilst looking for ““RegionService””, I stumbled upon LocalizationService, which has the GetCountryRegionForPlayerAsync function. So if you don’t want to setup a custom proxy for this, you could take the country of the first player (they’re the one who influence the server region) who joins the server and based off of that conclude the continent of the server. The average user is either way typically only interested in whether they’re on a server that is or isn’t 20 000 km away from them.

you’re correct, but I do have to point out that the true first player who start up the server may not always be consistent, and regions are not always guaranteed (ROBLOX may still place you in another region if it wishes to do so for good reasons, i.e. you get routed to a server based in Germany if you’re from France and all French servers are down)

1 Like

this is a real service btw i can prove this

i better not see ‘RegionService - a new way to get server region’ in Community Resources in a couple days

1 Like

you got my hopes up for nothing :broken_heart:

YESSSSS SIR I LOVE YOU IT WORKS

i put the other post as solution to troll others in the future

ROBLOX may still place you in another region if it wishes to do so for good reasons

Which is why I said in my previous reply that that method should only be used to get the continent of the server, since only a few countries host Roblox servers. Most if not all of i.e. Europeans get put in either the UK, the Netherlands, France and Germany.

usually they get put in eastern ukraine or moldova but alr

thanks, please consider marking my reply as a solution :slight_smile:

tried using this, but 99% of the time it returns “HTTP 429” from "return HttpService:GetAsync("https://ipapi.co/“..serverIP..”/json/“)”. pretty sure HTTP 429 is a rate limit error. any ideas on how you could get around this?

You can do this;

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

Players.PlayerAdded:Connect(function(player)
	local region = LocalizationService:GetCountryRegionForPlayerAsync(player)
	print(player.Name, region)
end)

Anything deeper may be used for tracking, which violates Roblox’s Terms of Use and Developer Policy. (don’t mean that to sound rude, I just can’t post or inform as deep as I can go by that rule)

2 Likes

I haven’t had issues at all, but there are a few reasons you get a 429

Like any async HTTP calls, you do need to rate-limit the script that calls it. I assume you have wrapped it in a pcall with a debounce or some sort of promise.

Keep in mind that you shouldn’t need to call this more than once per start-up.