How to ideally implement a player's failure when he gets caught between two platforms

Good morning,

sometimes I encounter problem in my game, the player gets caught between two platforms that translate for example, so I think the best solution to solve this problem is that during the jamming, the player fails instantaneously,

but how to implement please this solution has this problem in the most ideal way?

Thank you very much .

Cordially .

Probably use animation and trigger the state through script? @Bioshok7