How do I get the total players in a game using the roblox api?

Hello, I need to get the amount of players in a game through the api, whenever I try to get it to return !
the amount of players in a game it returns “nil”

This is the code I used, but whenever I try to add something to “.body”, for example: “body.data” it will return nil. (It returns all the normal things without anything extra added to “.body”)
Any help is appreciated.

local httpService = game:GetService("HttpService")
local ProxyService = require(script.Parent.ProxyService)
local Proxy = ProxyService:New('example.com', 'example')
print(Proxy:Get('https://games.roblox.com/v1/games?universeIds=1686885941').body)


1 Like

Sorry, I accidentally uploaded the second image twice

1 Like

Looks like an issue with whatever this “ProxyService” module you are using is. I assume this is the one that Froast (sentanos) made.

Check the server’s output on the heroku server to make sure the proxy is running.

You can use the games API:

https://games.roblox.com/docs#!/Games/get_v1_games

Your Get request should look something like this since ProxyService doesn’t automatically decode the body:

local decodedBody = httpService:JSONDecode(proxy:Get('https://games.roblox.com/v1/games?universeIds=100').body)
2 Likes

Why do you need to use the API? Just use #game.Players:GetPlayers() and use MessagingService to run that code on each server, then add the numbers up…

They’re looking for the total number of players in-game in all servers

1 Like

How would I make it only return the player count instead of all of the other data?

I know that… What do you mean?

I thought roblox removed proxy?

1 Like

No, rprxy just got shut down because they couldn’t host it anymore. Now you can just use rprxy.deta.dev/api/

1 Like

I can’t remember whether .data is automatically passed as .body but it should look something like this:

local decodedBody = httpService:JSONDecode(proxy:Get('https://games.roblox.com/v1/games?universeIds=100').body)

local active = decodedBody.data[1].playing

if that errors, it’s

active = decodedBody[1].playing
3 Likes

Im not sure if im explaining this right, but when you add “print(decodedBody.data)” it returns a bunch of other things like the games description, max server size, and a bunch of other things

1 Like

#players:GetPlayers() returns the amount of players in one specific server

1 Like

Why would you need this though? You just need the amount of players like you said…

There isn’t an API endpoint that specifically returns the amount of players in-game, you have to use the /games/ endpoint to get the amount of players in all servers.

1 Like

I literally just said how to do it…

1 Like

I’m not sure I understand. You said to use rprxy.deta.dev which is a public proxy, op wants to use a private one.

1 Like

I did not say to use a proxy? What do you mean?

I’m confused. You said to use #players:GetPlayers() or to use rprxy.deta.dev, both of which aren’t going to give the op what they want since there is no service that allows people to get the amount of players in all servers.

#players:GetPlayers() returns the amount of players in one specific server; the server in which the code is ran.

Yeah, I said to run that code on every server using MessagingService and then add the numbers up…