# How to fix my Verse code for UEFN boss AI

**URL:** <https://forums.unrealengine.com/t/how-to-fix-my-verse-code-for-uefn-boss-ai/1242173>\
**Category:** Verse\
**Tags:** unreal-engine, unreal-editor-for-fortnite, fortnite-creative, question, Blueprint, fortnite\
**Created:** [July 27, 2023, 10:05pm UTC](https://forums.unrealengine.com/t/how-to-fix-my-verse-code-for-uefn-boss-ai/1242173 "2023-07-27T22:05:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoeBroPro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JoeBroPro](https://forums.unrealengine.com/u/JoeBroPro)\
**Post date:** [July 27, 2023, 10:05pm UTC](https://forums.unrealengine.com/t/how-to-fix-my-verse-code-for-uefn-boss-ai/1242173/1 "2023-07-27T22:05:47Z")

</div>

I have a code for an AI boss that follows a player once a player activates a mutator zone. The problem is the AI enemy only targets one player instead of attacking the one who triggered the mutator zone. Can someone help me in fixing my code to do this?  
Here is what I have so far:

> using { /Fortnite.com/Devices }  
> using { /Verse.org/Simulation }  
> using { /UnrealEngine.com/Temporary/Diagnostics }  
> using { /Fortnite.com/Characters }  
> using { /UnrealEngine.com/Temporary/SpatialMath }  
> using { /Fortnite.com/Playspaces }

BossDevice := class(creative\_device):

PlayerChar : ?agent = false

@editable  
Bossprop : creative\_prop = creative\_prop{}

@editable  
Zonedevice : mutator\_zone\_device = mutator\_zone\_device{}

ProptranslationAxis : vector3 = vector3:  
X := 0.0  
Y := 0.0  
Z := -1.0

OnBegin():void=  
Zonedevice.AgentEntersEvent.Subscribe(OnTriggered)

OnTriggered(Agent: agent):void =  
spawn{FollowPlayer()}

FollowPlayer():void =

```
loop:
    Sleep(0.01)
    if (PlayerList := GetPlayspace().GetPlayers(), FortCharacter := PlayerList[0].GetFortCharacter[]):
        Playerpostion : vector3 = FortCharacter.GetTransform().Translation
        Proptranslation : vector3 = Bossprop.GetTransform().Translation

        VectorToPlayer : vector3 = Playerpostion - Proptranslation

        RadiansVectorToPlayer: float = ArcTan(VectorToPlayer.X, VectorToPlayer.Y) - (PiFloat / 2.0)

        NewRotation : rotation =MakeRotation(axis := ProptranslationAxis, AngleRadians := RadiansVectorToPlayer)

        Bossprop.MoveTo(Playerpostion, NewRotation, 1.0)

    else:
         break

```

---

<div class="post-metadata">

**Author:** ![realTreqy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/realtreqy/32/1113815_2.png) [@realTreqy](https://forums.unrealengine.com/u/realTreqy)\
**Post date:** [July 28, 2023, 1:05am UTC](https://forums.unrealengine.com/t/how-to-fix-my-verse-code-for-uefn-boss-ai/1242173/2 "2023-07-28T01:05:54Z")

</div>

Hey! 👋

Basically if I take a look at your code, you’re trying to get all players on the island, but as you said you only want the activating player.  
I can’t show you the fixed code, but I can help you understand it a little bit more:

- `if (PlayerList := GetPlayspace().GetPlayers(), FortCharacter := PlayerList[0].GetFortCharacter[]):`

With this line of code you’re not accessing the player that activated the Mutator zone.

To achieve what you want, you have to do this instead:

- You have to rather use the Agent that actually activated the mutator zone. You already used the `Subscribe()` event to start the function, but later on you didn’t do anything with that agent that you want to use.

---

<div class="post-metadata">

**Author:** ![JoeBroPro](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JoeBroPro](https://forums.unrealengine.com/u/JoeBroPro)\
**Post date:** [July 28, 2023, 9:23pm UTC](https://forums.unrealengine.com/t/how-to-fix-my-verse-code-for-uefn-boss-ai/1242173/3 "2023-07-28T21:23:31Z")

</div>

Sorry very new to this and trying to figure it out. So it has something to do with using the line where I used the subscribe function so I can save that particular player and put in in the line of code in the place of where if says PlayerList?

---

<div class="post-metadata">

**Author:** ![Kubes\_Content](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kubes\_Content](https://forums.unrealengine.com/u/Kubes_Content)\
**Post date:** [July 29, 2023, 11:55am UTC](https://forums.unrealengine.com/t/how-to-fix-my-verse-code-for-uefn-boss-ai/1242173/4 "2023-07-29T11:55:47Z")

</div>

Not the Subscribe function, but when you call FollowPlayer inside OnTriggered you should be calling FollowPlayer(Agent) rather than FollowPlayer() since OnTriggered’s Agent is activating the trigger.

(adjusting FollowPlayer to accept an agent as well)

```auto
FollowPlayer(Agent: agent):void =

```

Then within FollowPlayer you can replace

```auto
if (PlayerList := GetPlayspace().GetPlayers(), FortCharacter := PlayerList[0].GetFortCharacter[]):

```

with

```auto
if (FortCharacter := Agent.GetFortCharacter[]):

```
