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.
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.
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!
GetPlayers or GetChildren same thing xD
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.
Yeah but meh I doubt you often have non players stuff inside Players
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.
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?
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
game.Players.NumPlayers or #game.Players:GetChildren()
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
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.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
.NumPlayers property of Players Service.
yeah or #