Animation to only play when the player is Moving

UIS.InputBegan:Connect(function(input, gameProcessed)
  if gameProcessed then return end
  if input.KeyCode == Enum.KeyCode.LeftShift then
    hum.WalkSpeed = 26
    anim:Play()
  end
)

UIS.InputEnded:Connect(function(input, gameProcessed)
  if gameProcessed then return end
  if input.KeyCode == Enum.KeyCode.LeftShift then
    hum.WalkSpeed = 16
    anim:Stop()
  end
)

and it all works great. But the problem is that whenever the player presses the LeftShift Key, the animation will play without the player moving. Any ways to around this?

1 Like

By changing the WalkSpeed, your only changing the maximum speed of the player, If you want to prevent the animation from playing when the player press the shift key then just add an if statement check if the player is moving or not.

Theres multiply ways checking if player is running.

  1. Using UIS
  2. Using Humanoid.Running:Connect(function()
  3. Humanoid.MoveDirection

There are more but these are the main ones.

1 Like