Run System Help

I’m currently working on a smooth shift to run system, I’ve encountered a few problems that I do not know how to fix and was wondering if I could get some help!

Problem 1:
When the player jumps while running when they land the running animation no longer plays, instead the walking animation plays.

Problem 2:
If the player runs into a ladder instead of climbing it, it plays the running animation and kinda shuffles its way up the ladder.

Problem 3: If the player is running but stops pressing WASD but is still holding shift the run animation continues to play.

I don’t know how to fix these (I’ve tried), so if someone can help me that would be incredible!

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid", 10)

local Animation = Instance.new("Animation")
Animation.AnimationId = "rbxassetid://12599730012"
local AnimationTrack = Humanoid:LoadAnimation(Animation)

local TweenService = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")

local TweenSpeedUp = TweenService:Create(Humanoid, TweenInfo.new(1), {WalkSpeed = 35})
local TweenSpeedDown = TweenService:Create(Humanoid, TweenInfo.new(1), {WalkSpeed = 16})

local isMoving = false
local isShiftDown = false

local function TweenStart()
	if isMoving then
		TweenSpeedUp:Play()
	end
end

local function TweenEnd()
	TweenSpeedDown:Play()
end

local function UpdateAnimation()
	if isMoving and (Humanoid.MoveDirection.Magnitude > 0) then
		if isShiftDown then
			AnimationTrack:Play(1, 1, 1)
		else
			AnimationTrack:Stop(1, 1, 1)
		end
	else
		AnimationTrack:Stop(1, 1, 1)
	end
end

UIS.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		isShiftDown = true
		isMoving = (Humanoid.MoveDirection.Magnitude > 0)
		TweenStart()
		UpdateAnimation()
	end
end)

UIS.InputEnded:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		isShiftDown = false
		isMoving = (Humanoid.MoveDirection.Magnitude > 0)
		TweenEnd()
		UpdateAnimation()
	end
end)

Humanoid.Jumping:Connect(function(IsJumping)
	if IsJumping then
		isMoving = false
		AnimationTrack:Stop()
	end
end)

local stateConnection = Humanoid.StateChanged:Connect(function(old, new)
	if (old == Enum.HumanoidStateType.Freefall) or (new == Enum.HumanoidStateType.Landed) then
		if isMoving and (Humanoid.MoveDirection.Magnitude > 0) then
			UpdateAnimation()
		end
	end
end)

if Humanoid:GetState() == Enum.HumanoidStateType.Climbing then
	AnimationTrack:Stop()
end

THANKS!

1 Like

Use Humanoid.Running to play your sprinting animation.

1 Like

My script was put together with popsicle sticks and masking tape so I’m not sure how I could use that. Can you give me an example?

1 Like
Humanoid.Running:Connect(function()
     if isShiftDown then --sprinting i guess? then
          AnimationTrack:Play()
      else 
          AnimationTrack:Stop()
     end
end)
1 Like

Ahh, Thank you so much!!! This helps alot