Changing Parent's forces children onto the same z level

I have a script the sets it’s child’s scale to a negative so the sprite on it inverts when an empty that follows the cursor moves to the other side of the script’s object. Here is the code:

switch (transform.InverseTransformPoint(follower.position).x)
        {
            case < 0:
                sprite.localScale = new Vector3(-5, sprite.localScale.y, 0);
                break;
            case > 0:
                sprite.localScale = new Vector3(5, sprite.localScale.y, 0);
                break;
        }

I also have other sprites as children of the one getting flipped that show the other parts of the character’s body, and these other sprites frequently need to go over their parent. The problem is this code seems to force all the children of the object it flips to be on the same Z level as it, despite the fact it doesn’t touch anyone’s position, leaving all the numbers the same. I know it’s this code because commenting it out fixes the problem. I’ve tried setting the Z back to what it should be, but that doesn’t work since the number isn’t being changed in the first place. I can’t just get rid of it, so what do i do here?

First step would be to stop setting your Z scale to zero:

Here’s more:

The proper way to set scales:

NEVER set scale (or any part of scale) to zero or negative.

NEVER use Vector2 because that makes the third term (Z) zero.

ALWAYS use Vector3, and make sure that the .z is either 1.0f, or else your non-zero scale.

Similarly never set scale to Vector3.zero, especially in a UI, because this will cause layout divide-by-zeros and damage all your hierarchy with either NaN or Infinity.