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

Can I See How Many People Are On a Server With a Script?

Asked by 9 years ago

Just wondering if there's any way to find the number of players on a server using a script of some sort.

I know you can find pictures of players, game thumbnails, etc. So I wouldn't be surprised if I could find the number of players on a server.

0
.NumPlayers property of Players Service. M39a9am3R 3210 — 9y
0
yeah or # KoreanBBQ 301 — 9y

3 answers

Log in to vote
2
Answered by 9 years ago

NumPlayers

The Players service has a property called NumPlayers which is the number of players in the server. That would be the easiest way to get it.

local PlayersInServer = game.Players.NumPlayers

GetPlayers()

The other way would be by using the GetPlayers() method on the Players service. GetPlayers() returns a table with all the players in the server, and because it's a table, we can use the # operator on the table to return the amount of elements in the table, which in our case is the amount of players in the server.

local PlayersInServer = #game.Players:GetPlayers()

Both of these methods will always work fine. Hope this helped!

0
GetPlayers or GetChildren same thing xD KoreanBBQ 301 — 9y
0
But using GetChildren will return everything or anything inside the Players folder. By that I mean, it will return things that is not a Player. xPolarium 1388 — 9y
0
Yeah but meh I doubt you often have non players stuff inside Players KoreanBBQ 301 — 9y
0
So, Korean? Whats wrong with taking the extra precaution? Plus it's shorter and more inferred as to what the script is trying to do. DigitalVeer 1473 — 9y
View all comments (2 more)
0
Question? Would this work on seeing other server's players? Like if I had a lobby server, could I see how many people would be on one of the other servers? SpazzMan502 133 — 9y
0
Not with just this method. To access other servers you'll probably need to use API's or DataStores. I'm not too familiar with either of those though TurboFusion 1821 — 9y
Ad
Log in to vote
1
Answered by
KoreanBBQ 301 Moderation Voter
9 years ago

game.Players.NumPlayers or #game.Players:GetChildren()

Log in to vote
0
Answered by 9 years ago

NumPlayers or GetPlayers()

EDIT

NumPlayers is an easy way, Example: in the command bar i type "print(game.Players.NumPlayers)" and it prints 0 because im in studio, not play solo or something. GetPlayers() is when you want to get every player and do something with them, Example: Teleporting them all

-- this is an example

 for _, player in pairs(game.Players:GetPlayers()) do
    if player.Character then
        player.Character:MoveTo(Vector3.new(0, 50, 0))
    end
end

if you weed more info go to the wiki pages

0
I just neutralized your reputation on this answer. Please give more details with your answers before posting. Otherwise the asker may not know what you're talking about, and you may get moderated or downvoted for not giving explanation. M39a9am3R 3210 — 9y

Answer this question