How to get a server Location on Roblox

I don’t really know where to find API, I found the API from someone’s post

However, you can try to find it here maybe
https://www.google.com/search?q=Free+weather+api&rlz=1C1ONGR_enIN965IN965&sxsrf=APq-WBtMSQAYZUvsKdAU2L6zH3oqVLvMXQ%3A1650789718379&ei=Vg1lYtXbFuzp2roP9ZqSmA4&ved=0ahUKEwjV3oz2pqz3AhXstFYBHXWNBOMQ4dUDCA4&uact=5&oq=Free+weather+api&gs_lcp=Cgdnd3Mtd2l6EAMyBwgAELEDEEMyBAgAEEMyBAgAEEMyBQgAEIAEMgoIABCABBCHAhAUMgQIABBDMgQIABBDMgUIABCABDIECAAQQzIFCAAQgAQ6BwgjEOoCECc6BAgjECc6CggAELEDEIMBEEM6BgguEAoQQzoICAAQgAQQsQM6BwgjELECECc6DQguELEDEIMBENQCEAo6DgguEIAEELEDEIMBENQCSgQIQRgASgQIRhgAUPwHWPceYNwgaANwAXgAgAGBAogBshWSAQYwLjE2LjKYAQCgAQGwAQrAAQE&sclient=gws-wiz

1 Like

None of the values are hash tagged, I don’t want others to know my location, so I made it #### in reality, it does not return any hashtag values

you should use camelCasing, 2. that gets the server location, so there is no reason to put a playerAdded event, 3. you should be using requestasync.

2 Likes

It displays IP Address of whoever who clicks the link, so we make server in Roblox click the link

Also I don’t know if your allowed to display zip code thats some personal info, players might also think the game is dangerous

Oh sorry I did not know I typed funtion instead of function, a “c” is missing, thx for telling

It would be nice, if you told it in a better way, why don’t you explain it? you just told typo

2 Likes

You are theroretically making a huge mistake:

game.Players.PlayerAdded:Connect(function(plr)
    local success,errormessage = pcall(funtion() -- the script won't stop working at a line if its inside a pcall function
    task.wait(2) -- player loads fully
    local getasyncinfo = httpsservice:GetAsync(url) -- roblox server will get info from that link
    game.Workspace.ServerLocation.Value = "Server Location: "..string.sub(tostring(getasyncinfo),31,37) -- 31 - 37 is is the country name in 5 words
  end)

In this code you’re getting the server’s region every time a player joins, this is extraordinarily wasteful and if this practice were to be adopted in a large scale game(s), could potentially lead to a roblox-discord sorta situation where ip-api (the discord in this case) blocks or throttles requests made from roblox servers.

Instead, get this only once when the server starts up. Also, this information is not useful in studio and many developers do a lot of playtesting, so the request should ideally not go through in order to use the api less.

Also, it’s worth mentioning that ip-api also offers flags for the request url here. Which can be used to save resources on both roblox’s end and the API’s end, which contributes to the longevity of the API.

Here’s your script rewritten with a few useful things in mind:

if game:GetService('RunService'):IsStudio() then return end

local http = game:GetService('HttpService')
local whatever = workspace.ServerLocation

-- this url has flags that only return information that's specifically needed.
local url = "http://ip-api.com/json/?fields=16394"
local region_format = "%s, %s"

local response = http:JSONDecode(http:GetAsync(url))

if response.status == "success" then
    whatever.Value = string.format(
        region_format, 
        response.countryCode, 
        response.regionName
    )
end

-- Note that no error handling is required here.
5 Likes

Uh thx for telling that also
why does this return

{"status":"fail"}

image

How would we be able to view it? This would be insufficient just in Studio, Is there a UI for it to display in-game?

1 Like

either you’re using the endpoint wrong or ask the guy who made the API

2 Likes

Wdym?

You’d just make a UI yourself. In this tutorial Deadwoodx used a string value object under workspace, so you could just make a TextLabel, give it a local script, and set the text to the value of that object.

1 Like

For those who want to find more APIs on the internet
Check this out:

Its safe not a scam link, don’t worry

I’ve really been interested in this post, so I decided to make my own resource for all of you to enjoy, its called LocationService.

Heres the module:

Lets talk about the parameters: returnedData and allowUseInStudio

returnedData -- string: put in one of the strings listed in the decoded table above

allowUseInStudio -- boolean: if false, the module will error and prevent it from running in studio.

Huh, I just tried my best, to tell something, it would be nice if you have DM me the errors, so I can learn from it maybe, and fix the errors

i literally explained before that you cannot get the IP of any player, only the server lmfao

1 Like

Hello, where did you find that the first player to join a server determines its location? Do you have any more information on how roblox server location works?

Yes, I have recently explained how the server location system works in this post

Where did you find that information

Google, Youtube, Twitter and Documentation

Can you link me to the documentation