Hello, i have walking animation for my viewmodel. And when i walk, it starting playing animation. But when i stop, animation not stopping.
Script:
script.Parent:WaitForChild("Equiped").Event:Connect(function(arms)
player.Character.Humanoid.Changed:Connect(function()
local runninganim = arms.Humanoid:LoadAnimation(arms.Animations.WalkAnim)
if arms then
if player.Character.Humanoid.MoveDirection.Magnitude > 0 then
if not runninganim.IsPlaying then
print("Play")
runninganim:Play()
runninganim:AdjustSpeed(0.25)
end
elseif player.Character.Humanoid.MoveDirection.Magnitude <= 0 then
print("Stop") -- printing but animation isn't stopping
runninganim:Stop()
end
end
end)
end)
You are creating a new runninganim everytime the Humanoid.Changed event fires.
Easiest fix would be:
local runninganim
script.Parent:WaitForChild("Equiped").Event:Connect(function(arms)
player.Character.Humanoid.Changed:Connect(function()
if not runninganim then runninganim = arms.Humanoid:LoadAnimation(arms.Animations.WalkAnim) end
if arms then
if player.Character.Humanoid.MoveDirection.Magnitude > 0 then
if not runninganim.IsPlaying then
print("Play")
runninganim:Play()
runninganim:AdjustSpeed(0.25)
end
elseif player.Character.Humanoid.MoveDirection.Magnitude <= 0 then
print("Stop") -- printing but animation isn't stopping
runninganim:Stop()
end
end
end)
end)