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
7 years ago
Edited 7 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
7 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.

01-- api to get information from
02local api = "myapi?placeid=0"
03-- index of what page we're on - increments by 10 each time
04local index = 0
05-- amount of players we've counted
06local result = 0
07-- the last request we got
08local lastRequest
09 
10repeat
11    -- get the page with the index we have
12    local request = game.HttpService:GetAsync(api .."&startIndex=".. index)
13    -- decode it from json into a lua dictionary
14    request = game.HttpService:JsonDecode(request)
15    -- loop through the collection from the request (the servers)
View all 27 lines...
0
Many thanks, however it comes up with the error "Trust check failed" Wiscript 622 — 7y
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 — 7y
Ad
Log in to vote
0
Answered by 7 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 7 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