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()
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.
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.
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.