i dont know a script for this, i just want to print out the number of players playing my game, no i dont mean game.Players:GetPlayers()
i mean the overall amount in all servers, please help,
;-;
1 | local http = game:GetService( "HttpService" ) |
2 | local gameid = game.GameId --the game id |
3 |
4 | local dat = http:JSONDecode(http:GetAsync( "https://games.roblox.com/v1/games?universeIds=" ..gameid)) |
5 |
6 | print ( "People playing " , dat [ 0 ] .playing) |
i found a fix thanks to BradNewTypical, i just needed to make the url a proxy.
01 | local http = game:GetService( "HttpService" ) |
02 |
03 | local gameid = game.GameId |
04 |
05 |
06 | local body = http:JSONDecode(http:GetAsync( "https://games.rprxy.xyz/v1/games?universeIds=" .. gameid)) |
07 |
08 |
09 | local totalplrs = body.data [ 1 ] .playing |
10 |
11 |
12 | print ( "Players In Total: " .. totalplrs) |
Hi mahid786! We used to do game.Players.NumPlayers
, but that is deprecated now. Instead, try this:
1 | wait() |
2 | local NumPlayers = game.Players:GetChildren() |
3 | print (#NumPlayers) |
To count all the children of the players, use #NumPlayers
.
An example may be:
1 | if #NumPlayers > 2 then |
2 | print ( "There are more than 2 players!" ) |
3 | end |
This checks if the amount of players are more than 2.
Another example can be:
1 | script.Parent.Text = "There are " ..#NumPlayers.. " in the server!" |
That changes the text into: "There are " *number of players in the server* "in the server!"
I hope that my examples help you understand! If so, please accept my answer!
New Edit: I got this from the Developer Forum, so if you do not understand this, use this link.
01 | local place_id = 0 --place id there |
02 | function players_online(place_id) |
03 | local web = game.HttpService:GetAsync( "https://www.rprxy.xyz/games/" ..place_id) |
04 | local player_text = string.find(web, "Playing" ) -- find the online players section |
05 | local new = string.sub(web,player_text) |
06 |
07 | local number_start = string.find(new, ">" ) -- find where the number starts |
08 | new = string.sub(new,number_start) |
09 |
10 | local number_end = string.find(new, "<" ) -- find where the number ends |
11 | new = string.sub(new, 2 ,number_end- 1 ) |
12 |
13 | local players_online = string.gsub(new, "," , "" ) -- in case it's over 1000 players |
14 | return tonumber (players_online) |
15 | end |
Again, hope I helped.