SetPlayerName
Jump to navigation
Jump to search
setPlayerName
Changes a connected player's authoritative multiplayer name.
Syntax
bool setPlayerName(int playerId, string playerName)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
playerId |
int |
yes | The connected player whose name will be changed. |
playerName |
string |
yes | A unique name containing 3-16 ASCII letters, digits, spaces, underscores or hyphens. |
Returns
Returns true when the server accepts the new name; otherwise returns false.
Examples
Create a private /name command:
addCommandHandler("name", function(playerId, commandName, ...)
local requestedName = table.concat({...}, " ")
if setPlayerName(playerId, requestedName) then
outputChatBox("Your name is now " .. getPlayerName(playerId) .. ".", playerId)
else
outputChatBox("That player name is invalid or already in use.", playerId)
end
end)
Notes
- Available only in server-side resource scripts.
- Names are trimmed and must be 3-16 characters long.
- Allowed characters are A-Z, a-z, 0-9, spaces, underscores and hyphens. Consecutive spaces are rejected.
- Names must be unique among connected players; uniqueness is checked case-insensitively.
- Successful changes are replicated to clients and raise
onPlayerNameChange.