How should I go about reverting the player back to their idle animation?

I have a script that freezes the player by anchoring their humanoid root part.

However, if you’re walking while it happens, the walking animation continues.

My question is:
How do I stop this? How do I make it so your character is reverted back to idle animations? Also, when I unanchor the humanoid root part, I want everything to return to normal.

If the idle method for doing this is not anchoring the player, or if there are better ways of doing it, do share those as well. Anything that accomplishes what I want is helpful.