tool.Equipped:Connect(function()
if playing == false then
playing = true
track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action
track.Looped = true
track:Play()
end
end)
tool.Unequipped:Connect(function()
if playing == true then
playing = false
track:Stop()
end
end)
tool.Equipped:Connect(function()
while wait(0.1) do
if math.floor(script.Parent.Parent.HumanoidRootPart.Velocity.Magnitude) > 1 then
playing = true
track2 = script.Parent.Parent.Humanoid:LoadAnimation(anim2)
track2.Priority = Enum.AnimationPriority.Action
track2.Looped = true
track2:Play()
if track then
track:Stop()
end
break
else
if math.floor(script.Parent.Parent.HumanoidRootPart.Velocity.Magnitude) < 1 then
if not track then
playing = true
track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action
track.Looped = true
track:Play()
if track2 then
track2:Stop()
end
break
end
end
end
end
end)
tool.Unequipped:Connect(function()
if playing == true then
playing = false
if track then
track:Stop()
end
if track2 then
track2:Stop()
end
end
end)
If you want an idle animation to play, make sure the animation priority is set to Idle.
I tried remaking your script, tell me if this version works:
local Players = game:GetService("Players")
local Tool = script.Parent
local Player
local Character
Tool.Equipped:Connect(function()
Character = Tool.Parent
Player = Players:GetPlayerFromCharacter(Character)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local Animator = Humanoid and Humanoid:FindFirstChild("Animator")
if Humanoid and Animator then
local animation = script.Animation
local animationrack = Animator:LoadAnimation(animation)
animationrack:Play()
Tool.Unequipped:Connect(function()
animationrack:Stop()
end)
end
end)