# onTrailerAttach (Server)

> Fired on the server when a trailer is hitched to a vehicle. Cancelling the event unhitches the trailer.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Event
- **Side**: Server
- **Category**: Vehicles
- **Cancellable**: `cancelEvent`
- **URL**: https://wiki.mymp.gg/en/onTrailerAttach

## Syntax

```lua
addEventHandler("onTrailerAttach", root, function(vehicle towedBy) ... end)
```

## Handler parameters

| Name | Type | Description |
| --- | --- | --- |
| `towedBy` | `vehicle` | The vehicle now towing the trailer. |

## Source

The trailer.

## Example

```lua
addEventHandler("onTrailerAttach", root, function(towedBy)
    if isVehicleLocked(source) then
        cancelEvent()
    end
end)
```

## See also

- [onTrailerDetach (Server)](https://wiki.mymp.gg/en/onTrailerDetach.md): Fired on the server when a trailer is unhitched from the vehicle towing it.
- [onClientTrailerAttach (Client)](https://wiki.mymp.gg/en/onClientTrailerAttach.md): Fired on the client when a trailer is hitched to a vehicle.
- [getVehicleTowedByVehicle (Shared)](https://wiki.mymp.gg/en/getVehicleTowedByVehicle.md): Returns the trailer or vehicle this vehicle is towing.
- [getVehicleTowingVehicle (Shared)](https://wiki.mymp.gg/en/getVehicleTowingVehicle.md): Returns the vehicle that is towing this vehicle.
