Get a DataModel from JobId

I’m trying to make a friend join UI, where it displays all of your friends who are in your game which lets you join them as well.

I already know how to do all of that, but I also want to display some miscellaneous data such as server region and player count (of the server that said friend is in), but I’ve found no way to do that.

I’m just looking for a function or method that either retrieves the DataModel of said server or some info about it.

To get server region, you can send a request using HttpService to this url right here:

This website will get the server IP not yours, but if you visit this url from your brower then it will get your IP.

Heres an little example on how you do it.

local ip_website = "http://ip-api.com/json/"
local httpservice = game:GetService("HttpService")

local response = httpservice:GetAsync(ip_website)
if response then
  response =httpservice:JSONDecode(response)
  print(response)
end

Now to get the player count of the server you can easily do

#game.Players:GetPlayers()

The :GetPlayers() returns a table of all the players in the server, and if you put # (hashtag) in front of any table then it will return how many items there are in a table.

If there are 4 players in a server and if i do

local playersList = game.Players:GetPlayers()
local playersAmount = #playersList
print(playersAmount) -- Prints 4
1 Like

reminder, use pcalls for getasync as it might fail

2 Likes

Yeah, I know.
You can check I always uses pcall for everything including datastores or fetching data from an API.

The one I gave was an example.

you also should use RequestAsync instead. It has more customization like headers etc. And you can send all RESTful requests, like DELETE, POST, GET, PATCH, etc.

code sample:

local ip_website = "http://ip-api.com/json/"
local httpservice = game:GetService("HttpService")

local success, err = pcall(function()
	local response = httpservice:RequestAsync({
		Url = ip_website,
		Method = "GET"
	})
	
	print(httpservice:JSONDecode(response.Body))
end)

According to ip-api, you only can GET.
You cannot DELETE,POST,PATCH, so why not just use GetAsync.

you get more stuff, like headers, response status, status codes, etc. Request async should be used for HTTP requests.

I’m not talking about the player count in the server that you are currently in, maybe it would be a bit easier if I put it like this:

Player A is in the main menu.
Player B is already playing the game.

I want to know how to get the player count and region of Player B’s server from Player A’s server.

Then you can use DataStore, I don’t think theres an external way to get your friend’s player count since its abusing roblox’s apis.
You only can get your friend’s/person’s server info if you join it.

If you want server’s fps then you can use

workspace:GetRealPhysicsFPS()

That’s all what I know.