# llAttachToAvatar

*LSL function*

```lsl
void llAttachToAvatar(integer attach_point);
```

- `integer attach_point`: ATTACH_* constant or integer value representing the target attachment point.

- Energy: 10
- Permission: `PERMISSION_ATTACH`

Attaches the object to the avatar who has granted permission to the script. The object is taken into the users inventory and attached to **attach_point**.

If **attach_point** is zero, then the object attaches to the attach point it was most recently attached to.

```lsl title="How to use" frame="terminal"
llAttachToAvatar(0);
```

## Specification

:::note
Constants in *italic* require a viewer compatible with the [Project Bento](https://wiki.secondlife.com/wiki/Project_Bento_Skeleton_Guide) skeleton.
:::

<table>
	<tr>
		<td>

			****Body****

			| Constant | # | Name | Comment |
			| --- | --- | --- | --- |
			| [ATTACH_HEAD](/constants/ATTACH_HEAD/) | 2 | Skull | head |
			| [ATTACH_NOSE](/constants/ATTACH_NOSE/) | 17 | Nose | nose |
			| [ATTACH_MOUTH](/constants/ATTACH_MOUTH/) | 11 | Mouth | mouth |
			| [*ATTACH_FACE_TONGUE*](/constants/ATTACH_FACE_TONGUE/) | 52 | Tongue | tongue |
			| [ATTACH_CHIN](/constants/ATTACH_CHIN/) | 12 | Chin | chin |
			| [*ATTACH_FACE_JAW*](/constants/ATTACH_FACE_JAW/) | 47 | Jaw | jaw |
			| [ATTACH_LEAR](/constants/ATTACH_LEAR/) | 13 | Left Ear | left ear |
			| [ATTACH_REAR](/constants/ATTACH_REAR/) | 14 | Right Ear | right ear |
			| [*ATTACH_FACE_LEAR*](/constants/ATTACH_FACE_LEAR/) | 48 | Alt Left Ear | left ear (extended) |
			| [*ATTACH_FACE_REAR*](/constants/ATTACH_FACE_REAR/) | 49 | Alt Right Ear | right ear (extended) |
			| [ATTACH_LEYE](/constants/ATTACH_LEYE/) | 15 | Left Eye | left eye |
			| [ATTACH_REYE](/constants/ATTACH_REYE/) | 16 | Right Eye | right eye |
			| [*ATTACH_FACE_LEYE*](/constants/ATTACH_FACE_LEYE/) | 50 | Alt Left Eye | left eye (extended) |
			| [*ATTACH_FACE_REYE*](/constants/ATTACH_FACE_REYE/) | 51 | Alt Right Eye | right eye (extended) |
			| [ATTACH_NECK](/constants/ATTACH_NECK/) | 39 | Neck | neck |
			| [ATTACH_LSHOULDER](/constants/ATTACH_LSHOULDER/) | 3 | Left Shoulder | left shoulder |
			| [ATTACH_RSHOULDER](/constants/ATTACH_RSHOULDER/) | 4 | Right Shoulder | right shoulder |
			| [ATTACH_LUARM](/constants/ATTACH_LUARM/) | 20 | L Upper Arm | left upper arm |
			| [ATTACH_RUARM](/constants/ATTACH_RUARM/) | 18 | R Upper Arm | right upper arm |
			| [ATTACH_LLARM](/constants/ATTACH_LLARM/) | 21 | L Lower Arm | left lower arm |
			| [ATTACH_RLARM](/constants/ATTACH_RLARM/) | 19 | R Lower Arm | right lower arm |
			| [ATTACH_LHAND](/constants/ATTACH_LHAND/) | 5 | Left Hand | left hand |
			| [ATTACH_RHAND](/constants/ATTACH_RHAND/) | 6 | Right Hand | right hand |
			| [*ATTACH_LHAND_RING1*](/constants/ATTACH_LHAND_RING1/) | 41 | Left Ring Finger | left ring finger |
			| [*ATTACH_RHAND_RING1*](/constants/ATTACH_RHAND_RING1/) | 42 | Right Ring Finger | right ring finger |
			| [*ATTACH_LWING*](/constants/ATTACH_LWING/) | 45 | Left Wing | left wing |
			| [*ATTACH_RWING*](/constants/ATTACH_RWING/) | 46 | Right Wing | right wing |
			| [ATTACH_CHEST](/constants/ATTACH_CHEST/) | 1 | Chest | chest/sternum |
			| [ATTACH_LEFT_PEC](/constants/ATTACH_LEFT_PEC/) | 29 | Left Pec | left pectoral |
			| [ATTACH_RIGHT_PEC](/constants/ATTACH_RIGHT_PEC/) | 30 | Right Pec | right pectoral |
			| [ATTACH_BELLY](/constants/ATTACH_BELLY/) | 28 | Stomach | belly/stomach/tummy |
			| [ATTACH_BACK](/constants/ATTACH_BACK/) | 9 | Spine | back |
			| [*ATTACH_TAIL_BASE*](/constants/ATTACH_TAIL_BASE/) | 43 | Tail Base | tail base |
			| [*ATTACH_TAIL_TIP*](/constants/ATTACH_TAIL_TIP/) | 44 | Tail Tip | tail tip |
			| [ATTACH_AVATAR_CENTER](/constants/ATTACH_AVATAR_CENTER/) | 40 | Avatar Center | avatar center/root |
			| [ATTACH_PELVIS](/constants/ATTACH_PELVIS/) | 10 | Pelvis | pelvis |
			| [*ATTACH_GROIN*](/constants/ATTACH_GROIN/) | 53 | Groin | groin |
			| [ATTACH_LHIP](/constants/ATTACH_LHIP/) | 25 | Left Hip | left hip |
			| [ATTACH_RHIP](/constants/ATTACH_RHIP/) | 22 | Right Hip | right hip |
			| [ATTACH_LULEG](/constants/ATTACH_LULEG/) | 26 | L Upper Leg | left upper leg |
			| [ATTACH_RULEG](/constants/ATTACH_RULEG/) | 23 | R Upper Leg | right upper leg |
			| [ATTACH_RLLEG](/constants/ATTACH_RLLEG/) | 24 | R Lower Leg | right lower leg |
			| [ATTACH_LLLEG](/constants/ATTACH_LLLEG/) | 27 | L Lower Leg | left lower leg |
			| [ATTACH_LFOOT](/constants/ATTACH_LFOOT/) | 7 | Left Foot | left foot |
			| [ATTACH_RFOOT](/constants/ATTACH_RFOOT/) | 8 | Right Foot | right foot |
			| [*ATTACH_HIND_LFOOT*](/constants/ATTACH_HIND_LFOOT/) | 54 | Left Hind Foot | left hind foot |
			| [*ATTACH_HIND_RFOOT*](/constants/ATTACH_HIND_RFOOT/) | 55 | Right Hind Foot | right hind foot |

		</td>
		<td></td>
		<td>

			<table>
				<caption>**HUD**</caption>
				<tr>
					<th colspan="2">Constant</th>
					<th>Comment</th>
				</tr>
				<tr>
					<td>[ATTACH_HUD_CENTER_2](/constants/ATTACH_HUD_CENTER_2/)</td>
					<td>31</td>
					<td>HUD Center 2</td>
				</tr>
				<tr>
					<td>[ATTACH_HUD_TOP_RIGHT](/constants/ATTACH_HUD_TOP_RIGHT/)</td>
					<td>32</td>
					<td>HUD Top Right</td>
				</tr>
				<tr>
					<td>[ATTACH_HUD_TOP_CENTER](/constants/ATTACH_HUD_TOP_CENTER/)</td>
					<td>33</td>
					<td>HUD Top</td>
				</tr>
				<tr>
					<td>[ATTACH_HUD_TOP_LEFT](/constants/ATTACH_HUD_TOP_LEFT/)</td>
					<td>34</td>
					<td>HUD Top Left</td>
				</tr>
				<tr>
					<td>[ATTACH_HUD_CENTER_1](/constants/ATTACH_HUD_CENTER_1/)</td>
					<td>35</td>
					<td>HUD Center</td>
				</tr>
				<tr>
					<td>[ATTACH_HUD_BOTTOM_LEFT](/constants/ATTACH_HUD_BOTTOM_LEFT/)</td>
					<td>36</td>
					<td>HUD Bottom Left</td>
				</tr>
				<tr>
					<td>[ATTACH_HUD_BOTTOM](/constants/ATTACH_HUD_BOTTOM/)</td>
					<td>37</td>
					<td>HUD Bottom</td>
				</tr>
				<tr>
					<td>[ATTACH_HUD_BOTTOM_RIGHT](/constants/ATTACH_HUD_BOTTOM_RIGHT/)</td>
					<td>38</td>
					<td>HUD Bottom Right</td>
				</tr>
			</table>

			<table>
				<caption>**Special**</caption>
				<tr>
					<th colspan="2">Constant</th>
					<th>Comment</th>
				</tr>
				<tr>
					<td>[ATTACH_ANY_HUD](/constants/ATTACH_ANY_HUD/)</td>
					<td>-1</td>
					<td>A special constant representing all HUD attachment points when filtering.</td>
				</tr>
			</table>

		</td>
	</tr>
</table>

## Caveats

- Attach points can be occupied by multiple attachments.[^wiki-b6e0ca]
  - This was not always the case, previously if **attach_point** was occupied, the existing object was detached and the new attachment took it's place.
- Objects attached to the head (and any attachment position within the head) will not be visible in First Person view (aka [Mouselook](https://wiki.secondlife.com/wiki/Mouselook)) if "show attachments in mouselook" is disable.
- If **attach_point** is zero but the object was never previously attached, it defaults to the right hand ([ATTACH_RHAND](/constants/ATTACH_RHAND/)).
- If the object is already attached the function fails silently, regardless if the **attach_point** is a different [attach point](/functions/llGetAttached/). -- [SCR-137](https://wiki.secondlife.com/wiki/Template:Issues/SCR-137)

[^wiki-b6e0ca]: Multiple attachments per attach point were added as result of [SCR-277](https://jira.secondlife.com/browse/SCR-277)

## Examples

<details open>
<summary>Example 1</summary>

```lsl collapse={1-11, 17-33}
//-- rez object on ground, drop in this script, it will request permissions to attach,
//-- and then attach to the left hand if permission is granted. if permission is denied,
//-- then the script complains.
default
{
    state_entry()
    {
        llRequestPermissions( llGetOwner(), PERMISSION_ATTACH );
    }

    run_time_permissions( integer vBitPermissions )
    {
        if ( vBitPermissions & PERMISSION_ATTACH )
            llAttachToAvatar( ATTACH_LHAND );
        else
            llOwnerSay( "Permission to attach denied" );
    }

    on_rez(integer rez)
    {
        if (!llGetAttached() )        //reset the script if it's not attached.
            llResetScript();
    }

    attach(key id)
    {
        // The attach event is called on both attach and detach, but 'id' is only valid on attach
        if (id)
            llOwnerSay( "The object is attached to " + llKey2Name(id) );
        else
            llOwnerSay( "The object is not attached");
    }
}
```

</details>

## Known issues

From the issue templates included by the wiki article:

- VWR-12525 (bug): llAttachToAvatar() can cause parentless attachments that can subsequently crash the client when selected
- SCR-137 (nf): Allow llAttachToAvatar() to switch attachment locations
- SVC-890 (bug): llAttachToAvatar can cause a stack/heap collision in certain circumstances
- SCR-277 (nf): Add companion command to  llAttachToAvatar() to allow attaching multiple items in same attachment point

## See also

### Functions

- [llAttachToAvatarTemp](/functions/llAttachToAvatarTemp/) — Attach an object to any avatar but only temporarily
- [llDetachFromAvatar](/functions/llDetachFromAvatar/) — Detaches the object from the avatar
- [llGetAttached](/functions/llGetAttached/) — Gets the attach point number (that the object is attached to)

### Events

- [attach](/events/attach/)

---

*Source: [LlAttachToAvatar](https://wiki.secondlife.com/wiki/LlAttachToAvatar) on the Second Life Wiki. Content from the Second Life Wiki articles LlAttachToAvatar (revision 1194057, 2015-01-22), Template:LSL Constants Attachment (revision 1217598, 2024-11-06), Template:LSL Function/permission (revision 1200093, 2016-05-12), Template:Issues/VWR-12525 (revision 498223, 2009-09-29), Template:Issues/SCR-137 (revision 1148327, 2011-07-09), Template:Issues/SVC-890 (revision 425763, 2009-07-07) and Template:Issues/SCR-277 (revision 1163762, 2012-03-05), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/functions/llAttachToAvatar/
