Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Wiscript 622 Moderation Voter
6 years ago
Edited 6 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)

3 answers

Log in to vote
0
Answered by
DevNetx 250 Moderation Voter
6 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" Wiscript 622 — 6y
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 250 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

I can't say I know what it means, but try this http://wiki.roblox.com/index.php?title=API:Class/Players/GetPlayers :P

Log in to vote
0
Answered by 6 years ago

I'm not sure of any other solutions, but you can probably create a datastore and write the total amount of players in a server and add that up with the other input from all the other servers. Then just increment or decrement whenever a player leave/joins a server or when the server shuts down. Though this is just an idea, i've never done this before.

Answer this question