Garry's Mod Wiki

player.GetCount

  number player.GetCount()

Description

Gives you the player count.

Similar to #player.GetAll() but with better performance since the player table doesn't have to be generated. If player.GetAll is already being called for iteration, then using the # operator on the table will be faster than calling this function since it is JITted.

Returns

1 number
Number of players

Example

Sending message in chat every 300 secs.

timer.Create("CountAdvert", 300, 0, function() local playerCount = player.GetCount() -- Getting the number of players on the server local message = "There are currently " .. playerCount .. " people playing on the server." -- Our message -- Send in chat for everyone for _, ply in pairs(player.GetAll()) do ply:ChatPrint(message) end end)