# Sprite error when attempting to follow

**URL:** https://forum.makecode.com/t/sprite-error-when-attempting-to-follow/4200
**Category:** Help
**Created:** [October 31, 2020, 3:15am UTC](https://forum.makecode.com/t/sprite-error-when-attempting-to-follow/4200 "2020-10-31T03:15:54Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Murturspurg](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@Murturspurg](https://forum.makecode.com/u/Murturspurg)
#### Post date: [October 31, 2020, 3:15am UTC](https://forum.makecode.com/t/sprite-error-when-attempting-to-follow/4200/1 "2020-10-31T03:15:54Z")

</div>

The problem code is where I try to get the enemy sprite to follow the player sprite but it says the enemy doesn’t exist though the sprite is on the screen. I have tried fixing this but it never works. Anyway to fix this?

---

<div class="post-metadata">

### Author: ![charliegregg](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/charliegregg/32/2411_2.png) [@charliegregg](https://forum.makecode.com/u/charliegregg)
#### Post date: [October 31, 2020, 8:50am UTC](https://forum.makecode.com/t/sprite-error-when-attempting-to-follow/4200/2 "2020-10-31T08:50:43Z")

</div>

Can you attach the code?

---

<div class="post-metadata">

### Author: ![Murturspurg](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@Murturspurg](https://forum.makecode.com/u/Murturspurg)
#### Post date: [October 31, 2020, 2:35pm UTC](https://forum.makecode.com/t/sprite-error-when-attempting-to-follow/4200/3 "2020-10-31T14:35:13Z")

</div>

![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/b/b81589eab19dbd1ce87260ab6bcdbe33ba67b82a.png)

---

<div class="post-metadata">

### Author: ![SPerkins25](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@SPerkins25](https://forum.makecode.com/u/SPerkins25)
#### Post date: [October 31, 2020, 3:51pm UTC](https://forum.makecode.com/t/sprite-error-when-attempting-to-follow/4200/4 "2020-10-31T15:51:04Z")

</div>

I would use the local variable “sprite” that’s in that **on created loop**. I think “Zombie” refers to the most recent zombie created which could cause some issues with your code since you have 7 seconds worth of pauses in your code.

---

<div class="post-metadata">

### Author: ![UnsignedArduino](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/unsignedarduino/32/592_2.png) [@UnsignedArduino](https://forum.makecode.com/u/UnsignedArduino)
#### Post date: [October 31, 2020, 3:54pm UTC](https://forum.makecode.com/t/sprite-error-when-attempting-to-follow/4200/5 "2020-10-31T15:54:54Z")

</div>

FWIW, you should post a share link of your game instead of a picture. It makes it much easier for everyone.

---

<div class="post-metadata">

### Author: ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)
#### Post date: [October 31, 2020, 5:33pm UTC](https://forum.makecode.com/t/sprite-error-when-attempting-to-follow/4200/6 "2020-10-31T17:33:14Z")

</div>

Yes, the issue here is using zombie in the on created instead of the sprite in the event. The reason this is failing is pretty subtle, though - the on created handler runs synchronously (without breaking for other events), so it must complete before the `create sprite` will return.

This means that the zombie variable isn’t assigned a value until **after** the on created event(s) for that kind have finished running, so using zombie in there will always refer to the previous zombie (and for the first time, it’s undefined, causing the error you are seeing). When you use `sprite` instead there, it’s value will always be the sprite that has just been created
