Help making an attack animation stop the previous attack animation

  1. What do you want to achieve? Keep it simple and clear!

I wish to achieve a simple punch script that cycles through animations.

  1. What is the issue? Include screenshots / videos if possible!

I do not know how to make the last animation stop when the new animation is played, and this results in a wonky mess when the attacks are spammed as the ending of the previous animation will overlap with the beginning of the new one.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I did think of making the animations shorter to match the cooldown, but I wanted to keep the animations a little longer so that I could animate small details such as getting back into the idle stance and possible sword twirls, so on.

I tried implenting a simple

if track then
track:Stop()

but that did not solve anything, as I later figured each time the RemoteEvent is fired, a new track is created and it can not delete the previous one. Is there a way for me to make it possible that a new animation stops the old one, without the inconvenience of accidentally stopping ALL the players’ attack animations once a new player attacks (This is a server script)

		local anim = storage.M1S[tostring(combovalue)]
		local track = Humanoid.Animator:LoadAnimation(anim)
		track:Play()
		if combovalue >= #storage.M1S:GetChildren() then
			char:SetAttribute("M1Combo", 1)
		else
			char:SetAttribute("M1Combo", combovalue + 1)
		end
		task.wait(0.5)
		if debounces[plr] then
			debounces[plr] = nil
		end

This is the animations working properly:

And this is them once you attack continously

1 Like

Just set more prioritie for each animation in order like slash 1 , action1 and slash2 , action2

1 Like

You can use the “GetPlayingAnimationTracks” method to get the attack animations and stop them specifically each time you play a new animation.
Some rough example code…

for i, v in pairs(player.Character.Humanoid:GetPlayingAnimationTracks()) do
		if v.Name == [ANIMATION NAME] then
			v:Stop()
		end
	end
2 Likes

store the last animation track i guess?
I’m not sure if I’m understanding ur problem

1 Like

:GetPlayingAnimationTracks() returns me an animation named “Animation” that doesn’t give me much to work with in terms of name…

I modified the script so it instead checks for the animation ID not the name and now it works. Thank you.