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)
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)