How to Move an enemy back and forth on a platformer

The enemy is only going right because of a domino effect.

Try checking for states with a cooldown, or you can implement it just like how I implemented it by checking for an instance variable when the player/enemy is in collision with a flip object (See the GIF below):

Screencastfrom2024-07-1400-53-55online-video-cutter.com-ezgif.com-optimize