How to stop custom Idle animation when playing an animation?

Hello,

I want to let my custom Idle animation stop playing when my attack animation is playing. (I changed my custom Idle animation by going to Roblox’s animate script manually). I have tried to search for solutions on youtube, scriptinghelpers, devforum, etc., but didn’t get anything sadly. One of the solutions was AnimationPriority but that didn’t work as well.

Script:

game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	while char.Parent == nil do
		char.AncestryChanged:wait()
	end
	local animation = Instance.new("Animation")
	local hum = char:WaitForChild("Humanoid")
	animation.AnimationId = "http://www.roblox.com/asset/?id=7788468950"
track.Prioriy = Enum.AnimationPriority.Action  -- one of the solutions that didn't work
	track = hum:LoadAnimation(animation)

end)
game.ReplicatedStorage.Attack.OnServerEvent:Connect(function(plr,pos)
	track:Play() --animation plays but it overrides my custom idle animation
end)

Thanks for reading, any help is appreciated!

1 Like
game.Players.PlayerAdded:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	while char.Parent == nil do
		char.AncestryChanged:wait()
	end
	local animation = Instance.new("Animation")
	local hum = char:WaitForChild("Humanoid")
	animation.AnimationId = "http://www.roblox.com/asset/?id=7788468950"
track.Prioriy = Enum.AnimationPriority.Action --One of the solutions that didn't work
	track = hum:LoadAnimation(animation)
game.ReplicatedStorage.Attack.OnServerEvent:Connect(function(plr,pos)
	track:Play() --- whene you place it out the function script it dont know what track mean
end)
end)

Just tried putting “track” inside the RemoteEvent. It plays, but it still overrides my custom Idle animation.

That’s not what I am trying to achieve. What I am trying to do is have my Animation override my custom Idle animation.

change the idle animation to the animation id that you made

I changed it to the animation, but my Idle animation is completely gone because I have changed it manually inside Roblox’s Animate script. I want my animation just to play for a few seconds, then return to my original custom Idle animation. Thanks for the help, though.

https://developer.roblox.com/en-us/api-reference/function/Humanoid/GetPlayingAnimationTracks

Tried this. I also used print(track) to know which animations are going to be stopped, but sadly it just stops animations that aren’t in Roblox’s default animations such as Idle, Running, Walking, etc.

You can use:

    if Animation.IsPlaying ~= true then
       track:Play()
    end

or just check if the current pose of the humanoid is standing (idle)

 if pose ~= "Standing" then
 	track:Play()
 end

hope this helps!

Thanks for commenting, but I want to play the animation while the player is standing. It played the animation, but that isn’t the problem. The problem is that the animation plays while the Idle animation is playing too at the same time.

So you changed the idle animation ID and it still plays the old one while playing the new one at the same time?

No, it plays my custom Idle animation while playing an attack animation at the same time.

Just edited the post, sorry for misunderstandings.

1 Like