# touch

*LSL event*

```lsl
touch(integer num_detected)
```

- `integer num_detected`: Total number of touching agents detected (usable with llDetected* functions).

Triggered whilst an agent is clicking the task. It will continue to be triggered until the the prim/object is stopped being clicked (it triggers multiple times).

Triggered on touch start, each minimum event delay while held, and touch end.

```lsl title="How to use" frame="terminal"
touch(integer num_detected)
{

}
```

## Caveats

- If a prim [face](https://wiki.secondlife.com/wiki/Face) has [Shared Media](https://wiki.secondlife.com/wiki/Navigating_Shared_Media) enabled and the avatar's viewer supports this feature, LSL scripts will not detect touches on that face. Touches from older clients will be detected.
- Rigged mesh attachments do not support touch events, this is because you can steer your avatar/camera by click dragging your avatar body which is what the rigged mesh replaces. The only way to get a touch event on a rigged mesh attachment is via the right click context menu and clicking the "Touch" button.

## Examples

<details open>
<summary>You can use index 0 through (**num_detected**-1) with the various llDetected... functions to handle simultaneous touches at once.</summary>

For example, the following script shows the names of everyone touching it (click and hold) as floating text.

```lsl collapse={21-39}
list touchers;

default
{
    // Collect names of avatars touching the object.
    touch(integer num_detected)
    {
        integer i;
        for (i = 0; i < num_detected; ++i)
        {
            string name = llDetectedName(i);
            if (llListFindList(touchers, [name]) == -1)
            {
                touchers += name;
            }
        }
        llSetText("I am being touched by " + llList2CSV(touchers) + ".", <1,1,1>, 1);
    }

    // Remove names of avatars as they let go.
    touch_end(integer num_detected)
    {
        integer i;
        for (i = 0; i < num_detected; ++i)
        {
            string name = llDetectedName(i);
            integer index = llListFindList(touchers, [name]);
            touchers = llDeleteSubList(touchers, index, index);
        }
        if (llGetListLength(touchers) > 0)
        {
            llSetText("I am being touched by " + llList2CSV(touchers) + ".", <1,1,1>, 1);
        }
        else
        {
            llSetText("", <1,1,1>, 1);
        }
    }
}
```

</details>

<details>
<summary>For most purposes, it's usually enough to handle just with the first toucher e.g. [llDetectedKey](/functions/llDetectedKey/)(0).</summary>

```lsl
default
{
    touch(integer num_detected)
    {
        llOwnerSay("I am being touched by " + llDetectedName(0) + ".");
    }
}
```

</details>

## See also

### Functions

- [llSetTouchText](/functions/llSetTouchText/) — Set the pie menu's text for touch-action
- [llPassTouches](/functions/llPassTouches/) — Allows clicks captured by a child prim to be passed to the root as well

### Events

- [touch_start](/events/touch_start/)
- [touch_end](/events/touch_end/)

---

*Source: [Touch](https://wiki.secondlife.com/wiki/Touch) on the Second Life Wiki. Content from the Second Life Wiki article Touch (revision 1218821, 2026-04-30), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/events/touch/
