Idle Not Playing While Running

So I have a run script and the animation plays whenever the character is holding left shift and it increases player speed. However if the character is not moving but left shift is still being held the running animation will continue to play. I was wondering if anyone can update my script to play the idle animation if the character isn’t moving while the script is still active.

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://15718018186'
		PlayAnim = Character.Humanoid:LoadAnimation(Anim)
		PlayAnim.Priority = Enum.AnimationPriority.Movement
		PlayAnim:Play()
	end
end)

UIS.InputEnded:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 16  --default walk speed
		PlayAnim:Stop()
	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()
			end
		end
end)

Your condition is only if the player holds the LeftShift button but does not specifiy if the player is moving while he is pressing it. You could do so by simply adding the line:

if Character.Humanoid.MoveDirection > 0 then -- checks if char is moving

to your conditions.

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