How Can I Stop An Animation When A Player Walks?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to stop an animation when a character walks.
  2. What is the issue? Include screenshots / videos if possible!
    I want to stop an animation from playing whenever a character walks but I can’t find a solution to how.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve looked on the Dev Hub but couldn’t find anything. I’ve also tried using if Humanoid.MoveDirection ~= Vector3.new(0, 0, 0) then but it didn’t work either.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you! The script is local tool = script.Parent
    local Anim = Instance.new(“Animation”)
    Anim.AnimationId = “rbxassetid://7174194492”
    local track
    tool.Equipped:Connect(function()
    track = script.Parent.Parent.Humanoid:LoadAnimation(Anim)
    track.Priority = Enum.AnimationPriority.Action
    track.Looped = true
    track:Play()
    end)

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

-- This is an example Lua code block

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

2 Likes

try checking for the HumanoidRootPart’s velocity.

local Equipped = false-- set to true/false depending on whether the tool is equipped or not
local HumanoidRootPart = script.Parent.Parent.HumanoidRootPart

while true do
    if Equipped then
        if HumanoidRootPart.Velocity.Magnitude < 0.5 then
            track:Stop()
        else
            if not track.IsPlaying then
                track:Play()
            end
        end
    end
    wait()
end
1 Like

Try using Humanoid.Running instead, for example:

local equipped = false

tool.Equipped:Connect(function()
    equipped = true
    Humanoid.Running:Connect(function(speed)
        if equipped == true then --Without this, this function will keep running.
            if speed > 0 then
                track:Stop()
            else
                track:Play()
            end
        end
    end)
end)

tool.Unequipped:Connect(function()
    equipped = false
    track:Stop()
end)

This works perfectly fine for me. I use this all the time.

You don’t need a script, you can just use AnimationPriority, if it’s set to a level lower than the one of the walk animation it wi automatically stop

It works perfectly, thank you so much!

1 Like

No problem, glad I could help!