Please familiarize yourself with a debugger, it will save you a lot of time in the long run. I can’t tell you why your code crashes, but I can point out a flaw in your logic, you’re iterating through an array front to back and removing items as you go, this invalidates all indices you haven’t iterated through yet. You should iterate through the instances in reverse order, that way you won’t invalidate indices you haven’t iterated through yet.