I made a script that has custom holding animations for tools like idle and move animations and the script works fine until I stop moving where the moving animation does not stop when I stand still until the tool is unequipped. I have tried a lot of things to fix the bug like editing the code multiple times but they all result in the same thing.
local tool = script.Parent
local player = tool.Parent.Parent
repeat wait(1) until player.Character
local character = player.Character
local humanoid = character:WaitForChild('Humanoid')
local moving = false
local equipped = false
local idle = script:WaitForChild('Idle')
local move = script:WaitForChild('Move')
local idletrack = humanoid:LoadAnimation(idle)
local movetrack = humanoid:LoadAnimation(move)
tool.Equipped:Connect(function()
equipped = true
idletrack:Play()
end)
tool.Unequipped:connect(function()
equipped = false
moving = false
movetrack:Stop()
idletrack:Stop()
end)
humanoid.Running:Connect(function(speed)
if speed > 0 and equipped then
moving = true
elseif speed == 0 and equipped then
moving = false
end
end)
while wait(0.01) do
if moving and equipped then
movetrack:Play()
movetrack.Stopped:Wait()
if not moving and equipped then
movetrack:Stop()
else
movetrack:Play()
end
end
end
local tool = script.Parent
local player = tool.Parent.Parent
repeat wait(1) until player.Character
local character = player.Character
local humanoid = character:WaitForChild('Humanoid')
local moving = false
local equipped = false
local idle = script:WaitForChild('Idle')
local move = script:WaitForChild('Move')
local idletrack = humanoid:LoadAnimation(idle)
local movetrack = humanoid:LoadAnimation(move)
tool.Equipped:Connect(function()
equipped = true
idletrack:Play()
end)
tool.Unequipped:connect(function()
equipped = false
moving = false
movetrack:Stop()
idletrack:Stop()
end)
humanoid.Running:Connect(function(speed)
if speed > 0 and equipped then
moving = true
elseif speed == 0 and equipped then
moving = false
end
end)
task.spawn(function()
while task.wait() do
if moving and equipped then
idletrack:Stop()
movetrack:Play()
movetrack.Stopped:Wait()
else
movetrack:Stop()
end
end
end)
local tool = script.Parent
local player = script:FindFirstAncestorWhichIsA("Player")
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local moving = false
local equipped = false
local idle = script:WaitForChild("Idle")
local move = script:WaitForChild("Move")
local idletrack = humanoid:LoadAnimation(idle)
local movetrack = humanoid:LoadAnimation(move)
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:connect(function()
equipped = false
end)
humanoid.Running:Connect(function(speed)
if speed > 0 and equipped then
moving = true
elseif math.round(speed) <= 0 then
moving = false
end
end)
task.spawn(function()
while task.wait() do
if moving and equipped then
idletrack:Stop()
movetrack:Play()
elseif moving and not equipped then
idletrack:Stop()
movetrack:Stop()
elseif equipped and not moving then
movetrack:Stop()
idletrack:Play()
elseif not equipped and not moving then
idletrack:Stop()
movetrack:Stop()
end
end
end)