game:GetHostLocation()

As a Roblox developer, it is currently too hard to accurately get the hosting location of a Roblox server that is being played on.

If such a feature existed, it’d allow developers to do various things, such as improve matchmaking through use of prioritizing servers closer to the user, or even having certain builds/GUIs cater to the user in single-player games. More information/a proposed implementation can be found below.


Proposed Implementation

When the forum about the Server List Update was released, one of the answers to the FAQs was:

It would be useful if one of these tools allowed us to get the region in which the server is hosted. This can be used to allow players to join games in regions that are closest to them for optimal gameplay. Not only that, but it’d also allow developers to use this to customize certain aspects of their game.

Example: A single-player city game wants to customize the city based on where the server is located(Using “Nandos” as a fast-food resturant for a UK-based server versus using "Chick-Fil-a [:heart:] for US-based servers).

Here’s an example on how I was thinking it could be used/implemented:

local Region = game:GetHostLocation()

if Region == Enum.ServerHostRegion.USEast then
	print("Timezone: EST")
elseif Region == Enum.ServerHostRegion.USCentral then
	print("Timezone: CST")
end

And if desired, you could even take it a step further and have it return a special array with these values:

local HostData = game:GetHostLocation()

print(HostData.Country) --Prints "US"
print(HostData.Region) --Prints "East"

Of course all this can be subject to change, but overall I think it’d be a useful feature.

61 Likes

Another cool feature that @Link150 and some other guys at the ScriptingHelpers Discord came up with was if we were able to get the relative location(similar to what this function would return) of the player. Features like these would really put a lot more power in the hands of developers.

3 Likes

You can already do this with a fairly hacky method

Compare UNIX tick to the client tick. You then have the timezone diff (and can get the region).

8 Likes

Have you actually checked that this works? My gut feeling would say this is incorrect as they made a promise that server time is more-or-less synchronised across all servers.

1 Like

It only works if you compare global Unix time to the client tickets, not server tick.

1 Like

But the offset will be the same for every server that that client connects to, since server times should be synchronized globally (tick() and os.time() should return similar values on all servers). You can estimate the timezone of the client but that doesn’t give you the region of the server.

4 Likes

Can do a voting system. Assuming that Roblox’s matchmaking works properly, a majority of players should be in similar timezones and you should be able to make an educated guess as to where the server is located.

Yeah, it’s not as good as having a location, but I don’t think ROBLOX will allow this for privacy issues

@Flowtonio Also, for future reference, I recommenced not suggesting the API. I recommend instead that you use the supplied format and list the problem, not a solution.

I don’t know if staff will even read this considering it isn’t in the format
¯\(ツ)

Fair point. I edited the question a bit to follow the guidelines.

I noticed that this game: Tales from the Valley - Roblox was able to find the server host location and display it in the menu bar. Perhaps the creator @Arch_Mage could give us some insight on how he did it? :smiley:

1 Like

My guess is he GeoIPs the server address

1 Like

Yeah, as @Semaphorism suggested I just use a simple web service to retrieve information about the server.

Just send an HTTP GET request to this URL and it’ll give you enough details: http://ip-api.com/json/

Note that it isn’t always very accurate, however. e.g. it says Nevada for some servers even though Roblox doesn’t rent any servers in Nevada, etc.

Hope this helps.

UPDATE: Geo IP services are no longer accurate. Expose a way to get a server's region

47 Likes

I actually would’ve never thought of this. You’ve just helped me a ton, thanks! :smiley:

1 Like

You can also use longitude to determine the servers location based on time zone.

local longitude = http:JSONDecode(http:GetAsync('http://ip-api.com/json/')).lon
				
local host = 'NA'
		
if(longitude>-180 and longitude<=-105)then
	host = 'WUS'
elseif(longitude>-105 and longitude<=-90)then
	host = 'CUS'
elseif(longitude>-90 and longitude<=0)then
	host = 'EUS'
elseif(longitude<=75 and longitude>0)then
	host = 'EU'
elseif(longitude<=180 and longitude>75)then
	host = 'AS'
end
32 Likes

It would be nice for us to easily determine what region the server is in so we do not match players from different regions together which is horrible for UX and cause many gameplay problems.

This thread should be retitled after the problem rather than a proposed solution. The latter makes it hard to find and is easy to dismiss if the proposed solution is not agreeable.

e.g. “Expose a way to get server’s region”

2 Likes

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