Game Dev 2 Final Project code breaking my game

And now my towers simply wont dissapear with my destroy() and I don’t know why but for some reason putting it in a function makes it fail.

player = game.spawnPlayerXY("samurai", 40, 35)
player.maxSpeed = 17
player.maxHealth = 700
player.attackDamage = 20
spawnTime = 2

killTime = 4

def randomTower():
    if game.time >spawnTime:
        spawnTime += 2
        x = game.randomInteger(5,75)
        y = game.randomInteger(5, 63)
        fireTower = game.spawnXY("fire-spewer", x, y)
        if game.time > killTime:
            killTime += 2

while True:

The one detail I can see that is incorrect is this line of code. It’s backwards. The variable should always be on the left side while the value is on the right. Not sure if that is the only thing causing an issue though.

2 += spawnTime

Are you sure that is a type?

yea im pretty sure it is at least in game dev 1 not sure if its in game dev 2 tho

Hello and welcome to codecombat discourse! :tada: :tada: :tada: This is a cozy forum where you can share ideas, share fan art, get assistance for code, etc! Before you proceed, we hope that you review this topic, which shows all essentials of this board! Thanks!

if you have solved the level please check the box that says solution and someone will set it to [Solved].

But when I use it without the .destroy() I works just fine with the towers that shoot fireballs, and it was in the spawnable section so it should be in the game.