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!
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