How do i knock back a player when attacked by a player

i am working on a game where one player is trying to push the other player off of the platform. i can’t get the players to move back when hit. Does anyone else know how to do this. thanks and have a wonderful day.

perhaps on the hit event you could move the player player.X()-100 (or whatever amount of knockback you want) if player.X()<player2.X(), move the player player.X()+100 (or whatever amount of knockback you want) if player.X()>player2.X()?