0

# How do I get how many player's are online in a game by using a script?

Asked by 3 years ago
Edited 3 years ago

So, I know for a fact you can get some of the information from a place by simply using :GetProductInfo. You can get the place's name, description, even who created it. But, there's nothing on how to get the number of players online in a place. At least nothing that I could find. Does anyone know how to do this? If so it would be much appreciated

Also, how to get a place's image & thumbnail. (The Web API page doesn't have the proper thumbnail or Icon I need)

Note: (I know you can use :GetPlayers, but that would be for that server only, not the place's global players itself)

0
DevNetx 231
3 years ago

You can do this without datastores by using this api

Whilst that is an internal API and therefore you'll have to use a proxy to access it ingame, you can use that to loop through each page and get the amount of players.

Here's an example.

-- api to get information from
local api = "myapi?placeid=0"
-- index of what page we're on - increments by 10 each time
local index = 0
-- amount of players we've counted
local result = 0
-- the last request we got
local lastRequest

repeat
-- get the page with the index we have
local request = game.HttpService:GetAsync(api .."&startIndex=".. index)
-- decode it from json into a lua dictionary
request = game.HttpService:JsonDecode(request)
-- loop through the collection from the request (the servers)
for i,v in pairs(request.Collection) do
-- add to the result the amount of players in that server
result = result + tonumber(#v.CurrentPlayers)
end
-- set the last request to this request
lastRequest = request
-- increase the index by 10
index = index + 10
-- repeat until the amount of servers in the request is equal to zero
until #lastRequest.Collection == 0
-- output the amount of players we discovered
print("There are currently ".. result .. " players in this game!")

0
Many thanks, however it comes up with the error "Trust check failed" rodrigo455 578 — 3y
0
I mentioned in my answer that it is an internal API. ROBLOX blocks requests to anything on the *.roblox.com domain, meaning you'll need to use a third party proxy to access it. DevNetx 231 — 3y