# I just can't figure out the solution ;(

**URL:** <https://forum.makecode.com/t/i-just-cant-figure-out-the-solution/36983>\
**Category:** Help\
**Created:** [May 29, 2025, 5:29pm UTC](https://forum.makecode.com/t/i-just-cant-figure-out-the-solution/36983 "2025-05-29T17:29:52Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JaidenThePerson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jaidentheperson/32/16250_2.png) [@JaidenThePerson](https://forum.makecode.com/u/JaidenThePerson)\
**Post date:** [May 29, 2025, 5:29pm UTC](https://forum.makecode.com/t/i-just-cant-figure-out-the-solution/36983/1 "2025-05-29T17:29:52Z")

</div>

I’ve been working on a PVZ game for fun, and I’ve been trying to add in the code that prevents you from placing plants on tiles where plants already exist. I’ve created a variable called “CanPlant” and I’ve tried setting it to false whenever the player overlaps a plant, but it only ever works on the last peashooter I’ve placed.

If I have two peashooters, I cannot place another one on top of the last peashooter I just placed, but I can place it on any peashooter placed prior to it.

I also tried creating an invisible sprite that spawns when a peashooter spawns, and if you overlap with that it sets “CanPlace” to false, but the same issue arises.

I’m so close yet so far, does anyone know the solution? [https://arcade.makecode.com/S88710-92644-30700-44480](https://arcade.makecode.com/S88710-92644-30700-44480)

---

<div class="post-metadata">

**Author:** ![Bilangus](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bilangus/32/33219_2.png) [@Bilangus](https://forum.makecode.com/u/Bilangus)\
**Post date:** [May 30, 2025, 2:45am UTC](https://forum.makecode.com/t/i-just-cant-figure-out-the-solution/36983/2 "2025-05-30T02:45:37Z")

</div>

I would just ditch the variable approach and simply check if the crosshair overlaps with a sprite of the plant kind. Let me know if this helps.

---

<div class="post-metadata">

**Author:** ![Luke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/luke/32/32519_2.png) [@Luke](https://forum.makecode.com/u/Luke)\
**Post date:** [May 30, 2025, 2:17pm UTC](https://forum.makecode.com/t/i-just-cant-figure-out-the-solution/36983/3 "2025-05-30T14:17:59Z")

</div>

Overlap blocks are very glitchy I recommend ditching them and checking for the closest sprite to detect overlaps instead. I’ve run into overlap issues many times, most notably with my isometric city builder a few years ago  
You can read my topic on it for some more info. [[Tutorial] Making an Enemy Follow Multiple Sprites :snake:](https://forum.makecode.com/t/tutorial-making-an-enemy-follow-multiple-sprites/33914) it’s about making enemies follow multiple sprites by finding the nearest sprite. You can isolate the nearest sprite part of the code, combine it with a range the size of the sprite, and you get a perfect overlap function.

---

<div class="post-metadata">

**Author:** ![JaidenThePerson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jaidentheperson/32/16250_2.png) [@JaidenThePerson](https://forum.makecode.com/u/JaidenThePerson)\
**Post date:** [May 30, 2025, 5:12pm UTC](https://forum.makecode.com/t/i-just-cant-figure-out-the-solution/36983/4 "2025-05-30T17:12:25Z")

</div>

Oh yeah I tried that approach too, along with a coordinates based block is meant to prevent you from placing when the distance between the crosshait and peashooter are zero, both had the same issue as my other attempts…

---

<div class="post-metadata">

**Author:** ![JaidenThePerson](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jaidentheperson/32/16250_2.png) [@JaidenThePerson](https://forum.makecode.com/u/JaidenThePerson)\
**Post date:** [May 30, 2025, 5:12pm UTC](https://forum.makecode.com/t/i-just-cant-figure-out-the-solution/36983/5 "2025-05-30T17:12:56Z")

</div>

Ooh, since I have no clue how arrays work, I have a very frustrating solution, I can spawn an invisible sprite on each grid, to which my crosshair must overlap with it to place a plant, once a plant is placed, the sprite on that tile is destroyed.
