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.