How could I get the number of players in a server without doing this specific method?

This is what I have so far, it works. But I feel like there’s a simpler way to do it.

local NumPlayers = 0

game.Players.PlayerAdded:Connect(function(plr)
       local Players = game.Players:GetPlayers()
       NumPlayers = 0
       for i = 1, #Players do
             NumPlayers = NumPlayers + 1
       end
       print(NumPlayers)
end)
local Players = game:GetService("Players")

local Count = #Players:GetChildren()

Thank you for the much simpler way. I don’t know why I made it so difficult, lol.

1 Like

By the way you could also just use

local Count = #Players:GetPlayers()

if you only want to get the Players and because GetPlayers is meant for this

1 Like

Either will return the children of the Players service.

1 Like

Didn’t we just vote on that … the clear winner!

1 Like

Yes but GetChildren() will return an array of children of any class whereas GetPlayers() will return an array of player objects exclusively.

4 Likes

Hmmm … clearly not the winner then :unamused:
That’s what shortcuts get you. Hidden Errors!