InvalidOperationException: Collection was modifiedSolved
i keep getting this error and i have no clue what it is causing it. here is the code
 void EliminatePlayer(BasePlayer player)
        {
            if (isStarted && microplayers.Contains(player))
            {
                Item bnoc = ItemManager.CreateByItemID(-1262185308);
                Item bnoc2 = ItemManager.CreateByItemID(-1266045928);
                if (bnoc == null || bnoc2 == null)
                {

                }
                else
                {
                    bnoc.MoveToContainer(player.inventory.containerBelt);
                    bnoc2.MoveToContainer(player.inventory.containerWear);
                    player.inventory.containerBelt.SetLocked(true);
                    player.inventory.containerWear.SetLocked(true);
                }
                microplayers.Remove(player);
                if (microa.Count == 0)
                {
                    GameEnd();
                }
                    
            }

        }
        void GameEnd()
        {
            foreach(BaseEntity entity in microbuildingblocks)
            {
                entity.Kill();
            }
        }
        void OnTick()
        {
            foreach(BasePlayer player in microplayers)
            {
                if(player.IsSwimming())
                {
                    EliminatePlayer(player);
                }
            }
        }​
It states that collection was modified during a loop, you are using foreach and removing elements from the same collection so it throws an exception. Instead use another collection (or duplicate this with something like ToArray) or use backwards for loop
k thx
Locked automatically