Sprinting Animation Playing When Jumping

Hey everyone!
Today I ran across a problem that I cannot find a solution to. My problem is that when I jump while sprinting, the sprinting animation plays over the default Roblox jumping animation which I do not want. It also plays the running animation when I start sprinting while falling down.

Video:
Sorry for the bad quality I don’t know why it’s like that.
https://gyazo.com/9ef291208d69f7dca5e80b7c7599accc

Script:

-- Variables --
local UIS = game:GetService('UserInputService')
local player = game.Players.LocalPlayer
local hum = player.Character:WaitForChild("Humanoid")
local anim = hum:LoadAnimation(script:WaitForChild("RunningAnimation"))
local NormalWalkSpeed = 16
local NewWalkSpeed = 25
local running = false
repeat wait() until game.Players.LocalPlayer.Character
local character = player.Character

-- Code --
UIS.InputBegan:connect(function(key, gameProcessed)
	if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
		if character:WaitForChild("Humanoid").MoveDirection.Magnitude > 0 then
			character.Humanoid.WalkSpeed = NewWalkSpeed
			anim:Play()
			running = true
			while running do
				wait()
				if character:WaitForChild("Humanoid"):GetState() == Enum.HumanoidStateType.Seated then
					anim:Stop()
					character.Humanoid.WalkSpeed = NormalWalkSpeed
				end
			end
		end
	end
end)

UIS.InputEnded:connect(function(key, gameProcessed)
	if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false  then
		character.Humanoid.WalkSpeed = NormalWalkSpeed
		anim:Stop()
		running = false
		while not running do
			wait()
			if character:WaitForChild("Humanoid"):GetState() == Enum.HumanoidStateType.Seated then
				anim:Stop()
				character.Humanoid.WalkSpeed = NormalWalkSpeed
			end
		end
	end
end)

character.Humanoid.Running:Connect(function(speed)
	if speed <= 16 then
		-- Player is not moving
		running = false
		anim:Stop()
	elseif running and not anim.IsPlaying then
		anim:Play()
	end
end)

This is an issue with the animations priority. If you made the animation using the built in animator there is a tab where you can set the priority. Since it is a sprinting animation the priority should be set to Movement.

2 Likes