How to unanchor the player after an animation has stopped playing

I have a script that can anchor the player while the animation runs but don’t have any idea on how to keep the player unanchored when the animation ends, Any suggestions?

local Animation = script.Animation:Clone()
Animation.Parent = Character.HumanoidRootPart
if Animation:Play() then
Humanoid.WalkSpeed = 0 and Character.HumanoidRootPart.Anchored == true else return
end```

I am not 100% sure if this will help you, but on the roblox developer hub I found this:

How would I interpret this into this code?

Animation.Parent = Character.HumanoidRootPart
if Animation:Play() then
Humanoid.WalkSpeed = 0 and Character.HumanoidRootPart.Anchored == true else return
end```

I also found this on the developer hub, this should help explain it to you:

Thank you. I will try to use this in my animation

Couldn’t you add a wait for the duration of the animation then make the anchored value false?

This is pretty simple.

local character = characterInstance — define this yourself
local animation = character.Humanoid:LoadAnimation(animationInstance)
animation:Play()
character.HumanoidRootPart.Anchored = true — anchor after the animation starts playing

animation.Stopped:Wait() — wait until the animation stops, you can connect a functio(n) instead if you don’t want to yield the code
character.HumanoidRootPart.Anchored = false — unanchor the HumanoidRootPart after the code is done waiting for the animation to stop
1 Like

You may want to fix your script, though.

Here:

local Animation = script.Animation:Clone();
Animation.Parent = Character;

if (Animation.Playing) then
    humanoid.WalkSpeed = 0;
    character.HumanoidRootPart.Anchored = true;
else
    humanoid.WalkSpeed = 16; character.HumanoidRootPart.Anchored = false;    
end

Thank you, I’ve been stuck for the last week on this.