Stop is not a valid member of Animation

I am having a complete brain fart, I am trying to stop a animation in multiple models that exist and I get the error code that stop isn’t a valid member, am i missing something? I have tried looking at other posts along side the error I have but they don’t seem to do me any justice.

	for i,v in pairs(MainFootballTeam:GetChildren()) do
		v:WaitForChild("Animations").SnapStance.Animation:Stop()
		v:WaitForChild("Animations").SnapAnim:Stop()
		if v.Animations.SnapStance:FindFirstChild("Block") then
			v.Animations.SnapStance.Block:Stop()
		end
	end
	
	for i,v in pairs(AwayTeamPlayers:GetChildren()) do
			v:WaitForChild("Animations").SnapStance.Animation:Stop()
			v:WaitForChild("Animations").SnapAnim:Stop()
			if v.Animations.SnapStance:FindFirstChild("Block") then
				v.Animations.SnapStance.Block:Stop()
		end
	end

Stop() is not a method for the Animation class; what you meant to access was an AnimationTrack.

1 Like

So to access that would I have to write

v:WaitForChild("Animations").SnapStance.Animation.AnimationTrack:Stop() 
1 Like

or

local track = v.Humanoid:LoadAnimation(v.Animations.SnapStance.Animation)
track:Stop()

You create an AnimationTrack by calling LoadAnimation on either an Animator or Humanoid. Then you can store it somewhere (like as a value in an ObjectValue Instance).

-- Example
local animation = Object.Animation
local animationTrack = Player.Character.Humanoid.Animator:LoadAnimation(animation)
animationTrack:Play()

It would be preferred that you use v.Humanoid:GetPlayingAnimationTracks() since creating a new AnimationTrack for the same animation won’t affect the previously one made (what I’m saying is: If you want to stop the animation like this, it’ll create a new animation and stop that one instead of the old one).

local tracks = v.Humanoid.Animator:GetPlayingAnimationTracks()
for _, track in tracks do
   if track.Animation == v.Animations.SnapStance.Animation then
       track:Stop()
   end
end
3 Likes

Perfect! Works perfectly now, I appreciate the time and your help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.