How do i make an animation stop when the character moves?

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 my animation to stop playing when the character moves.

  2. What is the issue? Include screenshots / videos if possible!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yes I have, but no solutio ended up working

game.Players.PlayerAdded:Connect(function(plr)
–Player Commands
plr.Chatted:Connect(function(msg)
if msg == ‘emote1’ then
print(‘fusfushfs’)

  	local hum = plr.Character.Humanoid
  	local animation = Instance.new('Animation', hum)

  	animation.AnimationId = 'rbxassetid://15577850405'

  	local anim =		hum:LoadAnimation(animation)
  	
  	anim:Play()
  end

end)
end)

I havent actually tried anything to stop my animation other then setting it’s animation priority to “Action”, thinking that would fix my problem. It didnt.

Any help is appreciated, thank you :smiley:

2 Likes

1st of all, my eyes burn looking at this code format. Anyhow, you can use the humanoid.MoveDirection Property to do this.

–Player Commands
game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(msg)
        if msg == ‘emote1’ then
  	        local hum = plr.Character.Humanoid
  	        local animation = Instance.new('Animation', hum)
  	        animation.AnimationId = 'rbxassetid://15577850405'
  	        local anim = hum:LoadAnimation(animation)
  	        anim:Play()
            hum:GetPropertyChangedSignal("MoveDirection"):Connect(function()
                if (hum.MoveDirection.Magnitude) > 0 then
                   anim:Stop()
                end
            end)
        end
    end)
end)

this should work in my eyes.

If it does not, lmk

Thank you, this worked! But how do i properly format my code? This was my first post ever on the developper forum.

Well it depends. If you are typing on Studio, its really just making sure stuff is looking how I typed it. On the form, the code format works a bit diff. You can mess around with the format. Here is an example:

this is no space
 this is one space
     this is a tab

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.