Custom toolnone animation is sometimes not playing

I want the character’s toolnone animation to change and play, it works, but sometimes the normal toolnone animation plays and not the one that I want.

Example:

Here is where the problem occurs, this is a server script:

script.Parent.Equipped:Connect(function()
	local rayparams = RaycastParams.new()
	rayparams.FilterDescendantsInstances = script.Parent.Parent:GetDescendants()
	Hitbox.RaycastParams = rayparams
	Animate = script.Parent.Parent.Animate
	oldAnim = Animate.toolnone.ToolNoneAnim.AnimationId
	Animate.toolnone.ToolNoneAnim.AnimationId = script.Idle.AnimationId
end)

script.Parent.Unequipped:Connect(function()
	Animate.toolnone.ToolNoneAnim.AnimationId = oldAnim
end)

How do I fix this?

Nevermind, I solved it:

script.Parent.Equipped:Connect(function()
	local rayparams = RaycastParams.new()
	rayparams.FilterDescendantsInstances = script.Parent.Parent:GetDescendants()
	Hitbox.RaycastParams = rayparams
	Animate = script.Parent.Parent.Animate
	oldAnim = Animate.toolnone.ToolNoneAnim.AnimationId
	Animate.toolnone.ToolNoneAnim.AnimationId = script.Idle.AnimationId -- Setting the new animation
	for i, v in pairs(script.Parent.Parent.Humanoid:FindFirstChild("Animator"):GetPlayingAnimationTracks()) do -- Going through all the current playing animation tracks and stopping them
		v:Stop()
	end
	anim = script.Parent.Parent.Humanoid:LoadAnimation(Animate.toolnone.ToolNoneAnim)
	anim:Play() -- Playing the new animation because the normal animation script doesn't start it
end)

script.Parent.Unequipped:Connect(function()
	anim:Stop() -- Stopping the new animation because the normal animation script doesn't stop it
	Animate.toolnone.ToolNoneAnim.AnimationId = oldAnim -- Setting the old animation
end)
1 Like