Help with for each loop / logic issue

I have done something like this, I couldn’t get ForEach to work right, so it ended up more complicated than it needed to be:
I have an array of ints representing the indices and an array of the spawned actors.

Here is spawning the pawn (Spawns a player at cursor location)

I have this GetNumberForIndex macro which makes sure a unique index is used, so if I have players 1,2,3,4 placed and then delete player 3 in-game, the next player placed will be 3, and then 5 . With a ForEach and a Contains node, I kept getting, 3 and then 4 repeated instead of 5 for example (like what happened to you), so I done it this way with the macro instead:

Basically it just starts at 1 and checks if the array contains that number, if it gets to a number not in the array, it uses that as the next player index. The “ValueToStore”.

And then when you want to delete an actor, I done this. There’s a lot here you won’t need, basically I am removing the selected actor and its associated int from their arrays, and then deleting the actor. Make sure destroy actor is the last step though.