Note: This is using Game Maker and its GML language. So the code might be a little different than what you have seen.
Okay so I put this code in a Generator to create falling rocks:
timer += 1
if(timer >= 120)
{
if(PlayerCharacter.x < 14512 && PlayerCharacter.x > 8512) instance_create(PlayerCharacter.x + 2000,408,FallingRock)
timer = 0
}
if(x < 8512) instance_destroy()
I wanted the rocks to be destroyed when they got behind 8512 x position.
The problem? I was deleting the Generator, not the rocks!
So since I placed the Generator at below 8512 x position, it got deleted every time I started the game.
(Don't hate on me for using Game Maker. I'll be making a game in Javascript soon probably as well, and you'll see more hilarity!)