This is because each time you remove an item, the total array of those instances is re-sized. So if you have 50 blocks there and the first one is “0”, if you remove that “0” the next block in line will then become the new “0” and the total array will become 49 instead of 50. I am dealing with a bug caused from this same issue.
In my game, a player can mine ores. Lets say there are 5 iron ore nodes on my map. If a player mines an iron ore, my code properly removes that specific iron node from the game for 20 seconds. After 20 seconds, the iron ore respawns. If I wait for the ore to repsawn before I mine another ore, the whole process works fine, but if I mine an ore while waiting for another ore node to respawn, it will remove the wrong ore node or not remove one at all because the array has been changed from its original state.
I have no idea on what a workaround would look like, but that’s the problem.