How would I make a clean tool idle animation script?

So, I’m trying to make a tool idle animation for my RPG game. I understand how to do it, but this happens:


How would I make it, so the other animations aren’t affected? Just the idle plays and the walk and run ones stay the same. I would appreciate your help.

Script:

local tool = script.Parent
local anim = Instance.new("Animation")

anim.Name = "IdleAnim"
anim.AnimationId = "rbxassetid://90348512778317" 

local track

tool.Equipped:Connect(function()
	track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
	track.Priority = Enum.AnimationPriority.Idle
	track.Looped = true
	track:Play()
end)

tool.Unequipped:Connect(function()
	if track then
		track:Stop()
	end
end)

Anyone?

Fjweudioadnfm,nv

the idle animation’s priority shouldn’t be Movement. that’s why the Idle priority exists.

Well yes I’ve already fixed that, but I don’t know how to make it so the animation doesn’t affect the other animations.

To stop all other animations runing at the same time is a simple peace of code of

humanoid.Animator:GetPlayingAnimationTracks()

And uou can loop through that because it returns an array.

for i, Ani in humanoid.Animator:GetPlayingAnimationTracks() do
Ani:Stop()
end

[youanimation]:Play()
 

So you code will look like

local tool = script.Parent
local anim = Instance.new("Animation")

anim.Name = "IdleAnim"
anim.AnimationId = "rbxassetid://90348512778317" 

local track

tool.Equipped:Connect(function()
for i, Ani in humanoid.Animator:GetPlayingAnimationTracks() do
Ani:Stop()
end -- stops all animations that are playing.
	track = script.Parent.Parent.Humanoid.Animator:LoadAnimation(anim) -- loadanimation on humanoids is deprecated so use the animator (a child of the humanoid) when playing animations.
	track.Priority = Enum.AnimationPriority.Idle
	track.Looped = true
	track:Play()
end)

tool.Unequipped:Connect(function()
	if track then
		track:Stop()
	end
end)

First of all, there’s an error at line 10. So I fixed it, but it still does not work. The idle overrides the walk and jump and stuff.

Instead of playing the animation, you’d rather replace the idle animation straight from the character’s Animation script:

local tool = script.Parent

tool.Equipped:Connect(function()
	local character = tool.Parent

	character:WaitForChild("Animate").idle.IdleAnim:Destroy()
	local idleanim = Instance.new("Animation")
	idleanim.Parent = character:WaitForChild("Animate").idle
	idleanim.Name = "IdleAnim"
	idleanim.AnimationId = "rbxassetid://90348512778317" 
end)

tool.Unequipped:Connect(function()
	local character = tool.Parent

	character:WaitForChild("Animate").idle.IdleAnim:Destroy()
	local idleanim = Instance.new("Animation")
	idleanim.Parent = character:WaitForChild("Animate").idle
	idleanim.Name = "IdleAnim"
	idleanim.AnimationId = ADD DEFAULT IDLE ANIMATION HERE
end)

Never mind, I just implanted a system to check the players movement, and it works. Thanks for the suggestions!

1 Like

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