Stop is not a valid member of Animation "Workspace.NUTRICORP.Animate.run.RunAnim"

Well, I get this error when I want to stop the running and walking animation. I want to stop the animation because when I set Character.HumanoidRootPart.Anchored = true, the character stops but the animation continues, and then I want the default animations of the following script to stop

local Player = Players.LocalPlayer
local Character =  Player.Character or Player.CharacterAdded:wait(1)

Character.HumanoidRootPart.Anchored = true; Character.Animate.run.RunAnim:Stop(); Character.Animate.walk.WalkAnim:Stop()

I think you may be confusing an Animation | Roblox Creator Documentation with an AnimationTrack | Roblox Creator Documentation

An AnimationTrack is generated with you call :LoadAnimation() on an Animation object. The AnimationTrack has the :Stop() function you’re looking for but you are referencing an Animation object in your code.

2 Likes

So what do I have to do to stop the animation?

First you would have to find the AnimationTrack associated with the animation you’re trying to stop. Then you’d need to call :Stop() on it.

One way you could do this is to use Animator | Roblox Creator Documentation. When an animation is loaded on a Humanoid or AnimationController an Animator | Roblox Creator Documentation object is created. So assuming this is a humanoid you’re animating with you could do something like this:

local function stop_animation(animation: Animation, animator: Animator, fade_time: number?)
  local animation_tracks = animator:GetPlayingAnimationTracks();
  for _, animation_track in pairs(animation_tracks) do
    if (animation_track.Animation == animation) then
      animation_track:Stop(fade_time);
      return;
    end
  end
end

local animator = Character.Humanoid:FindFirstChild('Animator');
if (animator) then
  stop_animation(Character.Animate.run.RunAnim, animator);
  stop_animation(Character.Animate.run.WalkAnim, animator);
end

If you’re using the default Roblox animation script then there’s a pretty good chance these animations will just restart. You’re probably better off just making your own animation script if that’s the case.

1 Like

Almost correct but an “Animator” object is a child of the “Humanoid” object and is used to load animations.

Well unless you actually create that Animator object it isn’t there until you call :LoadAnimation on a humanoid or AnimationController. You can also call LoadAnimation on an Animator object but most people just call it on the Humanoid or AnimationController which is why I explained it the way that I did.

Humanoid:WaitForChild("Animator")

Can be performed before any animation is loaded.

Or you could load the animation on the humanoid and avoid all of that nonsense.