# setServerPassword (Server)

> Changes the password to join the server. Players already in stay.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Server
- **Category**: Server
- **URL**: https://wiki.mymp.gg/en/setServerPassword

## Syntax

```lua
bool setServerPassword([string password = nil])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `password` | `string` | The new password. Without it, or empty, the server is open. *(default: `nil`)* |

## Returns

`true` once the password is set; `false` if it is over 32 characters long or has a space.

## Example

```lua
addCommandHandler("lock", function(player, command, password)
    setServerPassword(password)
end)
```

## See also

- [getServerPassword (Server)](https://wiki.mymp.gg/en/getServerPassword.md): Returns the password a player has to give to join.
