Run Script Issue

I have a run script and if left shift is being held down while the character is standing still it plays the animation. Can anyone add something to my script so that the run animation won’t play when idling.

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)

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) and Character.Humanoid.MoveDirection > 0 then
		Character.Humanoid.WalkSpeed = 35  --run speed
		local Anim = Instance.new('Animation')
		Anim.AnimationId = 'rbxassetid://15720702879'
		PlayAnim = Character.Humanoid.Animator:LoadAnimation(Anim)
		PlayAnim.Priority = Enum.AnimationPriority.Movement
		PlayAnim:Play()
    elseif input.KeyCode == Enum.KeyCode.Space then
        PlayAnim:Stop()
	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)

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