Garry's Mod Wiki

Garry's Mod Wiki

  number player.GetCount()

Description

Returns the active 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.
Players who are currently connecting to the server will not be counted. See function: player.GetCountConnecting

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 player.Iterator() do ply:ChatPrint(message) end end)

This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.

Page content is automatically updated four times a day. Edits and history are not available.

Last Parsed: Loading...