Help cancelling an animation when another plays

I’ve made a script where when the player clicks a punching animations plays and damages anyone nearby with a humanoid. However I also have another script where when the player double taps W the players speed increases and plays a running animations.

When the player begins to run and punch at the same time both animations in sync with each other like this:

I wonder if anyone could help me with a way to stop the running animation from playing when ever the player clicks to punch. Keep in mind the scripts are different. The running animation is a local script and the punching animation is a local script which fires towards a script using a remote event.

Keep in mind the code:
for i,v in pairs(Character.Humanoid:GetPlayingAnimationTracks()) do v:Stop() end
Tends to be buggy and when it’s performed instead of ending the running animation every animation stops. Both animation priority’s are set to action

1 Like

I believe that’s because of your priorities. If they’re both action, when another players, it’ll just override the other. If you set the running to Movement priority, the punch action will still override because it utilises the legs and arms, torso and others.

In my opinion, maybe trying to balance what animation controls what limb so you can sync it properly would be best. you can do this using the locking feature that like hides the limb from being used in the animation editor

1 Like

Hmm interesting. Thank you for the advice

2 Likes
Humanoid:GetPlayingAnimationTracks()

Isn’t buggy, from what you describe it’s doing exactly what it’s supposed to do (get every animation track regardless of priority), if you want to stop tracks of certain priorities then consider doing the following.

for _, animation in ipairs(humanoid:GetPlayingAnimationTracks()) do
	if animation.Priority == Enum.AnimationPriority.Action then --Only target action priority animations.
		animation:Stop()
	end
end
4 Likes

Thank you. Didn’t realise you could do that.

How would i implement this into a script that looks like this:
local green = script.Parent.Green

green.Touched:Connect(function(hit)
local player = game:GetService(“Players”):GetPlayerFromCharacter(hit.Parent)

local Character = player.Character
local Humanoid = Character:WaitForChild("Humanoid")

if player then
	

			local Animation = Instance.new("Animation") 
			Animation.AnimationId = "rbxassetid://10522159670"  

			local Track = Humanoid.Animator:LoadAnimation(Animation)
			Track:Play()


			Track.Looped = true



			task.wait(10)


	Track.Looped = false
end

end)

One way to implement a way to stop an animation is by doing

for i,v in pairs(Humanoid.Animator:GetPlayingAnimationTracks()) do					
			if v.Name == "Name Of Animation You Want To End" then					
				  v:Stop()	
			end	
	end

This only works in local scripts I think. Correct me if I’m wrong.

2 Likes

This is working great, thanks u solved my problem quick and easily!