Code keeps failing

This is dynamic. You could use a more reliable way to refer to a character “A B or C” by giving them an ID like a GUID, storing pointers to them or simply by storing all actors in an array and looping over the elements of that array.