getPlayerCount | Multi Theft Auto: Wiki Skip to content

getPlayerCount

Client-side
Server-side
Shared
Needs checking

This function was partially migrated from the old wiki. Please review manually:

  • Missing section: Shared implementation of getPlayerCount

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


This function returns the number of players currently connected to the server.

Note

#getElementsByType("player") works the same as this function but also works client side unlike this function.

Syntax

getPlayerCount ( )

Code Examples

server

This example displays a chat message with the number of players connected to the server when a player joins or quits.

function playerCount ( )
outputChatBox ( "There are now " .. getPlayerCount() .. " players on this server!" )
end
addEventHandler ( "onPlayerJoin", root, playerCount )
addEventHandler ( "onPlayerQuit", root, playerCount )

See Also