Run Animation Issue

I have a run script that plays a run animation when holding down left shift, the problem with this is if your holding left shift and you aren’t moving it will still play the animation. I don’t want this, I want the idle animation to play even if the playing isn’t moving while holding left shift. I was wondering if anyone could add something to my script that will stop the animation from playing if the playing isn’t moving.

Here is my run script:

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 35  --run speed
		local Anim = Instance.new('Animation')
		Anim.AnimationId = 'rbxassetid://15720702879'
		PlayAnim = Character.Humanoid:LoadAnimation(Anim)
		PlayAnim.Priority = Enum.AnimationPriority.Movement
		PlayAnim:Play()
		if Character.Humanoid.MoveDirection < 0 then
			PlayAnim:Stop()
		end
	end
end)

UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 16  --default walk speed
		PlayAnim:Stop()
		if Character.Humanoid.MoveDirection < 0 then
			PlayAnim:Stop()
		end
	end
end)

UIS.InputBegan:connect(function(input)
		if input.KeyCode == Enum.KeyCode.Space then
			PlayAnim:Stop()
			wait(.8)
			if Character.Humanoid.WalkSpeed == 35 then
			PlayAnim:Play()
			if Character.Humanoid.MoveDirection < 0 then
				PlayAnim:Stop()
			end
			end
		end
end)

You are checking the MoveDirection only when you press and let go of shift, you’d need to check this in a loop and then cancel it if the player is moving, like a RunService loop.

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