GetPlayerName
getPlayerName
Returns the authoritative multiplayer name of a connected player.
Syntax
string getPlayerName(int playerId)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
playerId |
int |
yes | The connected player identifier. |
Returns
Returns the player's current name as a string, or false when the player is not connected.
Examples
Greet a player when they join:
addEventHandler("onPlayerJoin", function(playerId)
local name = getPlayerName(playerId)
if name then
outputChatBox("Welcome, " .. name .. "!")
end
end)
Notes
- Available only in server-side resource scripts.
- Player names are authoritative on the server and are replicated to connected clients.