# llTeleportAgentGlobalCoords

*LSL function*

```lsl
void llTeleportAgentGlobalCoords(key agent, vector global_coordinates, vector region_coordinates, vector look_at);
```

- `key agent`: UUID of the owning avatar to teleport.
- `vector global_coordinates`: Global coordinates vector of the target region (obtained via llRequestSimulatorData).
- `vector region_coordinates`: Target coordinates vector within the destination region.
- `vector look_at`: Position vector within the region (or unit direction vector if out of region) that the agent faces upon landing.

- Energy: 10
- Permission: `PERMISSION_TELEPORT`

Teleports an **agent** to **region_coordinates** within a region specified by **global_coordinates**.

A region's global coordinates can be retrieved using `llRequestSimulatorData("region name", DATA_SIM_POS)`

If the destination is in the current region, the avatar will land facing **look_at** as a position within that region. Otherwise, **look_at** is treated as a unit direction.

The combination of [llRequestSimulatorData](/functions/llRequestSimulatorData/) and [llTeleportAgentGlobalCoords](/functions/llTeleportAgentGlobalCoords/) allows agents to be teleported to regions by region name.

```lsl title="How to use" frame="terminal"
llTeleportAgentGlobalCoords(NULL_KEY, ZERO_VECTOR, ZERO_VECTOR, ZERO_VECTOR);
```

## Caveats

- **This function can only teleport the owner of the object** (unless part of an [Experience](https://wiki.secondlife.com/wiki/Category:Experience_Tools)).
- Teleports are throttled
- This function cannot be used in a script in an object attached using [llAttachToAvatarTemp](/functions/llAttachToAvatarTemp/).
- Sitting avatars cannot be teleported using this function. You must [llUnSit](/functions/llUnSit/) them first.
- This function does not override a parcel's teleport settings, i.e. if the parcel has a landing zone enabled the avatar will be teleported there.
- If the script is part of an experience that the avatar has granted permission, then this function may teleport them without being the owner and it will override parcel teleport routing.
- When **look_at** treated treated as a direction, a valid input should be `<llCos(angle), llSin(angle), 0.0>`.
- In other words, it should be a **unit vector** corresponding to the avatar turning **angle** radians from north.

## Examples

<details open>
<summary>Basic example:</summary>

```lsl collapse={1-11}
default
{
    touch_start(integer num_detected)
    {
        llRequestPermissions(llGetOwner(), PERMISSION_TELEPORT);
    }

    run_time_permissions(integer perm)
    {
        if (PERMISSION_TELEPORT & perm)
        {
            vector global_coord = <232704, 291072, 0>;
            vector region_pos = <122, 122, 40>;
            llTeleportAgentGlobalCoords(llGetPermissionsKey(), global_coord, region_pos, ZERO_VECTOR);
        }
    }
}
```

</details>

<details>
<summary>Similar to the above, but also keeps track of current global coordinate and adjusts the **look_at** value based on whether the destination is the current region or a different one. This ensures that the avatar will always be facing the same direction regardless of whether they're teleporting within the region or to another one.</summary>

The script keeps track of the current region's global coordinate in **state_entry** and **changed** events, which is later used to check whether the destination has the same global coordinates.

```lsl collapse={1-42}
vector current_region;

default
{
    state_entry()
    {
        // Get current global coordinate when the script starts.
        llRequestSimulatorData(llGetRegionName(), DATA_SIM_POS);
    }

    changed(integer change)
    {
        if (!(change & CHANGED_REGION)) return;

        // Get current region coordinate when entering a new region.
        llRequestSimulatorData(llGetRegionName(), DATA_SIM_POS);
    }

    dataserver(key query, string data)
    {
        // Save llRequestSimulatorData response.
        current_region = (vector)data;
    }

    touch_start(integer num_detected)
    {
        llRequestPermissions(llGetOwner(), PERMISSION_TELEPORT);
    }

    run_time_permissions(integer perm)
    {
        if (!(PERMISSION_TELEPORT & perm)) return;

        vector global_coord = <232704, 291072, 0>;
        vector region_pos = <122, 122, 40>;

        float angle = 45 * DEG_TO_RAD;
        vector look_at = <llCos(angle), llSin(angle), 0>;

        if (current_region == global_coord) {
            // When teleporting within the current region, we should use a position within the region instead.
            look_at = region_pos + look_at;
        }

        llTeleportAgentGlobalCoords(llGetPermissionsKey(), global_coord, region_pos, look_at);
    }
}
```

</details>

<details>
<summary>Older example:</summary>

```lsl collapse={1-44, 50-79}
string simName = "Help Island Public";
vector simGlobalCoords;

vector landingPoint = <128.0, 128.0, 24.0>;

key owner;

default
{
    on_rez(integer start_param)
    {
        llResetScript();
    }

    changed(integer change)
    {
        if (change & CHANGED_OWNER)
            llResetScript();
    }

    state_entry()
    {
        owner = llGetOwner();

        llRequestPermissions(owner, PERMISSION_TELEPORT);
        llRequestSimulatorData(simName, DATA_SIM_POS);
    }

    touch_start(integer total_number)
    {
        key id = llDetectedKey(0);

        if (id == owner)
        {
            if (simGlobalCoords == ZERO_VECTOR)
            {
                llOwnerSay("Config error, tp request was denied. Please try again!");
                llResetScript();
            }
            else
            {
                llOwnerSay("Teleporting you to: http://maps.secondlife.com/secondlife/"
                    + llEscapeURL(simName) + "/" + (string)llRound(landingPoint.x)
                    + "/" + (string)llRound(landingPoint.y) + "/" + (string)llRound(landingPoint.z) + "/");

                llTeleportAgentGlobalCoords(owner, simGlobalCoords, landingPoint, ZERO_VECTOR);
            }
        }
        else
        {
            // llRegionSayTo is faster than llInstantMessage and we can assume
            // that the touching avatar is within the same sim

            llRegionSayTo(id, PUBLIC_CHANNEL,
                "Sorry, I can't tp you. You're NOT my owner!");
        }
    }

    run_time_permissions(integer perm)
    {
        // if permission request has been denied (read ! as not)
        if (!(perm & PERMISSION_TELEPORT))
        {
            llOwnerSay("I need permissions to teleport you!");
            llRequestPermissions(owner, PERMISSION_TELEPORT);
        }
    }

//  dataserver event only called if data is returned
//  or in other words, if you request data for a sim that does
//  not exist this event will NOT be called

    dataserver(key query_id, string data)
    {
        simGlobalCoords = (vector)data;
        // llOwnerSay("Sim global coords: " + (string)simGlobalCoords);
    }
}
```

</details>

## History

Date of Release [24/07/2012](https://wiki.secondlife.com/wiki/Release_Notes/Second_Life_Server/12#12-07-24-262437)

## Known issues

From the issue templates included by the wiki article:

- BUG-4062 (bug): llTeleportAgent() and llTeleportAgentGlobalCoords() can break any script in any attached object that contains a changed event.
- SVC-7987 (bug): llTeleportAgent always points in the positive Y direction on teleport

## See also

### Functions

- [llRequestSimulatorData](/functions/llRequestSimulatorData/) — Useful for requesting simulator position
- [llTeleportAgent](/functions/llTeleportAgent/) — Teleporting agents to a landmark or position in the region.

---

*Source: [LlTeleportAgentGlobalCoords](https://wiki.secondlife.com/wiki/LlTeleportAgentGlobalCoords) on the Second Life Wiki. Content from the Second Life Wiki articles LlTeleportAgentGlobalCoords (revision 1215142, 2023-10-19), Template:LSL Function/avatar (revision 1179236, 2013-06-15), Template:Issues/BUG-4062 (revision 1191579, 2014-06-23), Template:Issues/SVC-7987 (revision 1199724, 2016-03-13), Template:LSL Function/position (revision 1169387, 2012-06-18), Template:LSLP (revision 1169053, 2012-06-13) and Template:LSL Function/permission (revision 1200093, 2016-05-12), CC BY-SA 3.0.*

---

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