Garry's Mod Wiki


  number player.GetCount()


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.


1 number
Number of players


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)