# toggleControl (Server)

> Turns one of a player's controls on or off. Their client stops passing that control to the game, even with its key held down.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Server
- **Category**: Controls
- **URL**: https://wiki.mymp.gg/en/toggleControl-server
- **Counterpart**: Also exists on the client, with its own implementation: [toggleControl (Client)](https://wiki.mymp.gg/en/toggleControl-client.md)

## Syntax

```lua
bool toggleControl(player thePlayer, string control, bool enabled)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `thePlayer` | `player` | The player. |
| `control` | `string` | The control's name, case insensitive. |
| `enabled` | `bool` | `true` to turn it on, `false` to turn it off. |

## Returns

`true` if the order was sent to the client. `false` if the element is not a player or the control name does not exist.

The server keeps the state it sent, which `isControlEnabled` returns later.

## Example

```lua
addEventHandler("onPlayerVehicleEnter", root, function(vehicle)
    toggleControl(source, "vehicle_fire", false)
    toggleControl(source, "vehicle_secondary_fire", false)
end)
```

### Coming from MTA

Besides MTA's controls, MYMP has `block` (melee block) and `reload`.

## See also

- [isControlEnabled (Server)](https://wiki.mymp.gg/en/isControlEnabled-server.md): Tells whether one of a player's controls is on, going by what the server sent to their client.
- [toggleAllControls (Server)](https://wiki.mymp.gg/en/toggleAllControls-server.md): Turns all of a player's controls on or off at once. The order goes to their client.
- [setControlState (Server)](https://wiki.mymp.gg/en/setControlState-server.md): Presses or releases one of a player's controls as if it were a key. The order goes to their client, which applies it as setControlState on the local player.
- [toggleControl (Client)](https://wiki.mymp.gg/en/toggleControl-client.md): Turns one of the local player's controls on or off. A control that is off does not reach the game, even with its key held down.
