# setElementAttachedOffsets (Shared)

> Changes the offset, the rotation and, if asked, the socket of an attached element.

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

## Syntax

```lua
bool setElementAttachedOffsets(element element [, float x, y, z = 0, 0, 0, float rx, ry, rz = 0, 0, 0, string|int socket = nil])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `element` | `element` | The attached element. |
| `x, y, z` | `float` | Offset from the target, or a vec3. *(default: `0, 0, 0`)* |
| `rx, ry, rz` | `float` | Rotation relative to the target, or a vec3. *(default: `0, 0, 0`)* |
| `socket` | `string\|int` | Where on the target to attach: a ped's bone (its MTA id or its rig name) or a vehicle's or object's component or frame. A number only works when the target is a ped, a player or an object. Without a socket, the current one is kept. *(default: `nil`)* |

## Returns

`true` if it changed. `false` when the target has no such socket.

## Example

```lua
local vehicle = createVehicle("infernus", 1544.0, -1675.0, 13.6)
local ped = createPed("male01", 1544.0, -1675.0, 15.0)
attachElements(ped, vehicle, 0, 0, 1.2)
setElementAttachedOffsets(ped, 0, -1, 1.2, 0, 0, 180)
```

### Note

Given a parent element such as `resourceRoot`, it also changes the offsets of every element below it, but the result returned is only the element's own.

## See also

- [getElementAttachedOffsets (Shared)](https://wiki.mymp.gg/en/getElementAttachedOffsets.md): Reads the offset, rotation and socket an element is attached with.
- [attachElements (Shared)](https://wiki.mymp.gg/en/attachElements.md): Hangs one element on another. From then on it follows the target until it is detached.
- [detachElements (Shared)](https://wiki.mymp.gg/en/detachElements.md): Detaches an element from the element it hangs on. It stays where it is.
