# Teleport randomly to one of three teleporters after kill

**URL:** <https://forums.unrealengine.com/t/teleport-randomly-to-one-of-three-teleporters-after-kill/2337772>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [February 16, 2025, 11:48pm UTC](https://forums.unrealengine.com/t/teleport-randomly-to-one-of-three-teleporters-after-kill/2337772 "2025-02-16T23:48:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![GiordanoDeFiori](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GiordanoDeFiori](https://forums.unrealengine.com/u/GiordanoDeFiori)\
**Post date:** [February 16, 2025, 11:48pm UTC](https://forums.unrealengine.com/t/teleport-randomly-to-one-of-three-teleporters-after-kill/2337772/1 "2025-02-16T23:48:36Z")

</div>

Hi,  
I have this code that instantly respawns you and teleport to selected teleported. I wanted you make it teleport you to random teleporter from list. I created 2 lists using array and tried to shuffle through that list but I don’t know how my code should look.

```auto
InstantRespawn := class(creative_device):

    respawnposition: vector3=vector3{X:= 250.00, Y:= 0.01, Z:= 161.9}

    @editable
    ElimMachine : elimination_manager_device = elimination_manager_device{}
    @editable
    TeleporterTeam1 : teleporter_device = teleporter_device{}
    @editable
    TeleporterTeam2 : teleporter_device = teleporter_device{}

    NowRespawn(Agent: agent)<suspends>:void=
        Sleep(0.1)
        Agent.Respawn(respawnposition, rotation{})
        TeleporterTeam1 .Teleport(Agent)
        TeleporterTeam2 .Teleport(Agent)

    SelfEliminated(Agent:agent):void=
        spawn{NowRespawn(Agent)}

    OnBegin<override>()<suspends>:void=
        ElimMachine.EliminatedEvent.Subscribe(SelfEliminated)

```

---

<div class="post-metadata">

**Author:** ![4venzor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@4venzor](https://forums.unrealengine.com/u/4venzor)\
**Post date:** [February 17, 2025, 1:09am UTC](https://forums.unrealengine.com/t/teleport-randomly-to-one-of-three-teleporters-after-kill/2337772/2 "2025-02-17T01:09:18Z")

</div>

```auto
InstantRespawn := class(creative_device):

    respawnposition: vector3=vector3{X:= 250.00, Y:= 0.01, Z:= 161.9}

    @editable
    ElimMachine : elimination_manager_device = elimination_manager_device{}
    @editable TeleportersTeam1 : []teleporter_device = array{}
    @editable TeleportersTeam2 : []teleporter_device = array{}

    NowRespawn(Agent: agent)<suspends>:void=
        Sleep(0.1)
        Agent.Respawn(respawnposition, rotation{})
        Random := GetRandomInt(0,5)

        if (Teleporter := TeleportersTeam1[Random]):
            Teleporter.Teleport(Agent)
        
        if (Teleporter := TeleportersTeam2[Random]):
            Teleporter.Teleport(Agent)

    SelfEliminated(Agent:agent):void=
        spawn{NowRespawn(Agent)}

    OnBegin<override>()<suspends>:void=
        ElimMachine.EliminatedEvent.Subscribe(SelfEliminated)

```

---

<div class="post-metadata">

**Author:** ![Mineblo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mineblo/32/1203575_2.png) [@Mineblo](https://forums.unrealengine.com/u/Mineblo)\
**Post date:** [February 17, 2025, 4:00am UTC](https://forums.unrealengine.com/t/teleport-randomly-to-one-of-three-teleporters-after-kill/2337772/3 "2025-02-17T04:00:18Z")

</div>

The code seems correct, is your code not working at all or just asking for improvements?

> [@4venzor](#):
>
> ```auto
> if (Teleporter := TeleportersTeam1[Random]):
> Teleporter.Teleport(Agent)
>         
> if (Teleporter := TeleportersTeam2[Random]):
> Teleporter.Teleport(Agent)
> 
> ```

Also I assume here ^ you have the actual teleporters device filted by team otherwise players will always spawn on team 2 teleporters

---

<div class="post-metadata">

**Author:** ![GiordanoDeFiori](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GiordanoDeFiori](https://forums.unrealengine.com/u/GiordanoDeFiori)\
**Post date:** [February 17, 2025, 6:29pm UTC](https://forums.unrealengine.com/t/teleport-randomly-to-one-of-three-teleporters-after-kill/2337772/4 "2025-02-17T18:29:59Z")

</div>

I found the problem with that code. It works fine when I get Eliminated but when I Eliminate it’s not working . It’s because there is no EliminationEvent in the code I think. What would be the best way to change that part of code so it works both when I get eliminated and eliminate?

```auto
    OnBegin<override>()<suspends>:void=
        ElimMachine.EliminatedEvent.Subscribe(SelfEliminated)

```

---

<div class="post-metadata">

**Author:** ![4venzor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@4venzor](https://forums.unrealengine.com/u/4venzor)\
**Post date:** [February 17, 2025, 7:35pm UTC](https://forums.unrealengine.com/t/teleport-randomly-to-one-of-three-teleporters-after-kill/2337772/5 "2025-02-17T19:35:55Z")

</div>

If you want to teleport the player that did the Eliminating the Eliminated Event will not work since it only return’s the Agent that was Eliminated, to make it teleport the Agent that did the eliminating you could use → EliminationEvent

```auto
OnBegin<override>()<suspends>:void=
        ElimMachine.EliminatedEvent.Subscribe(SelfEliminated)
        ElimMachine.EliminationEvent.Subscribe()

```

---

<div class="post-metadata">

**Author:** ![GiordanoDeFiori](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@GiordanoDeFiori](https://forums.unrealengine.com/u/GiordanoDeFiori)\
**Post date:** [February 17, 2025, 8:08pm UTC](https://forums.unrealengine.com/t/teleport-randomly-to-one-of-three-teleporters-after-kill/2337772/6 "2025-02-17T20:08:40Z")

</div>

I tried doing it before but I get this problem:

 ![ss321](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/b/3/ab30f720ed5665bd82e105cdd7e84c66305de9f3.png)  
I changed “Agent” to “?Agent” but now I get this when I hover over “Agent” in this part of code:

```auto
spawn{NowRespawn(Agent)}

```

“This function parameter expects a value of type agent, but this argument is an incompatible value of type ?agent.(3509)”

```auto
    Elimination(Agent:?agent):void=
        spawn{NowRespawn(Agent)}

    OnBegin<override>()<suspends>:void=
# ElimMachine.EliminatedEvent.Subscribe(SelfEliminated)
        ElimMachine.EliminationEvent.Subscribe(Elimination)

```

---

<div class="post-metadata">

**Author:** ![4venzor](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@4venzor](https://forums.unrealengine.com/u/4venzor)\
**Post date:** [February 18, 2025, 12:18am UTC](https://forums.unrealengine.com/t/teleport-randomly-to-one-of-three-teleporters-after-kill/2337772/7 "2025-02-18T00:18:26Z")

</div>

This should fix that.

```auto
   Elim(Agent : ?agent): void =
        if (MaybeAgent := Agent?):
            spawn{NowRespawn(MaybeAgent)}

    OnBegin<override>()<suspends>:void=
        ElimMachine.EliminatedEvent.Subscribe(SelfEliminated)
        ElimMachine.EliminationEvent.Subscribe(Elim)

```
