Getting current player count using WebAPI and HTTP Service?

Assuming you want to know how to process the data it’s pretty simple.
The data is stored in a JSON format (but it will return a table with HttpService:JSONDecode)

Here’s accessing the player count of the example:

Eample
local body = game:GetService("HttpService"):JSONDecode(res) --res would be the response from the server

local playerCount = body.data[1].playing
print(playerCount)

Expected Output: 0

(Havent tested, just typed it out here might be some complications…)

8 Likes

Thank you very much for your help! :slight_smile:

Would like to thank everyone else who helped too!

1 Like

What is 'res???

2 Likes

What do i do with “res”???

i keep getting this error
image

1 Like

Plus i’ve put my Test game URL and i got this error
image

(Sorry for the late reply // necrobump)

res is the response from the server – it’s the result of a GET request. Here’s an example:

local url = "https://games.roblox.com/v1/games?universeIds={UniverseIDs}"

local res = game:GetService("HttpService"):GetAsync(URL) 

-- Then paste the other code

This obviously won’t work because:

  1. You need the universe ID
  2. You need to proxy the request since Roblox does not allow you to use Roblox’s web apis from the game server.

However, this is the basics of how it works

2 Likes

So, in that case, how would the script be?
I just need to change the URL to my game URL or i need to do more things?

sorry i’m a bit bad at this topic :sweat_smile:

technically no, all that needs changing is the URL and pasting the rest of the code

but you need to 1 past the ID of the universe (NOT THE PLACE ID) and then proxy it (you can do it yourself – there are many tutorials in #resources for it).

2 Likes

1 year late but i got this

1 Like

replace games.roblox.com with games.roproxy.com or another proxy

1 Like

Does not work either, it gives me that bad request error.
image
The code:

Turn on HttpService permission in your game Settings. 3 years later…

Extremely early response! good job, haha.

1 Like

Not to be rude or anything like that but I perfectly KNOW I need to have it ON.
If i wouldn’t know i’d get a whole different error.

Alright! You´re stuck on this post for 2.5 yrs already!

I KNOW HAHAHAHHAHA, it’s been a rough time trying to understand all this :sob: :sob: :sob: