Roblox Sprint animation wont stop playing after jump

  1. What do you want to achieve? Keep it simple and clear!
    When my character sprints and jumps, i want the jump animation to play, and then the sprint animation when the player lands
  2. What is the issue? Include screenshots / videos if possible!
    My current code works if the player jumps and lands sprint anim plays again, but the issue is when the player falls from a small height the sprint animation doesnt play but the character still sprints
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried getting humanoid state when running but it only works if falling from a height (character jumping)

code:

game:GetService("UserInputService").InputBegan:Connect(function(input) --gamerfortnite
	if input.KeyCode == Enum.KeyCode.LeftShift and Humanoid.MoveDirection.Magnitude > 0 then
		RunningTween:Play()
		SprintAnim:Play(0.3)
		Sprinting = true		
		repeat task.wait() until not game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.LeftShift) or Humanoid.MoveDirection.Magnitude <= 0	
		Sprinting = false	
		SprintAnim:Stop(0.2)
		WalkingTween:Play()
	end
end)

game:GetService('RunService').RenderStepped:Connect(function(dt)
	local tool2b2t =  Character:FindFirstChildWhichIsA("Tool")
	if not tool2b2t and Sprinting == false then
		game.ReplicatedStorage.Values.Springt.Value = false		
	elseif not tool2b2t and Sprinting == true then
		Humanoid.WalkSpeed = 20
	end

	if Sprinting == true then
		game.ReplicatedStorage.Values.Springt.Value = true
	else
		game.ReplicatedStorage.Values.Springt.Value = false
	end
end)

Humanoid.StateChanged:Connect(function(old, new) -- You dont have to use these but we will
	if new == Enum.HumanoidStateType.Running and Sprinting then
		SprintAnim:Play()
	elseif new ~= Enum.HumanoidStateType.Running then
		SprintAnim:Stop()
	end
end)

this is the whole code, not really important (i think), what is important is this:

Humanoid.StateChanged:Connect(function(old, new)
	if new == Enum.HumanoidStateType.Running and Sprinting then
		SprintAnim:Play()
	elseif new ~= Enum.HumanoidStateType.Running then
		SprintAnim:Stop()
	end
end)

when the player jumps their state goes to jump, so i detect when it chagnes to run and is sprinting, but if u fall from a small height roblox doesnt change it because of delays im guessing, is there another way to detect if the player falls at all or something?

I ran into a really similar issue earlier because I was also using Play() and Stop() for switching between different states and it messed up a bit of code. Realized that animation priorities exist and if you set them in this order jump > sprint > walk and then keep them always “on” but toggled individually through their priorities (higher priority overrides lower priority) it’s wayy easier to do

i dont quite understand what you mean with that

You can add a “if new == Enum.HumanoidStateType.Landed and Sprinting then” function so you can make it play the animation.

Humanoid.StateChanged:Connect(function(old, new)
	if new == Enum.HumanoidStateType.Running and Sprinting then
		SprintAnim:Play()
	elseif new == Enum.HumanoidStateType.Landed and Sprinting then
		SprintAnim:Play()
	elseif new ~= Enum.HumanoidStateType.Running then
		SprintAnim:Stop()
	end
end)

Thanks, i modified your code a little and it helped, ty

Humanoid.StateChanged:Connect(function(old, new) -- You dont have to use these but we will
	if new == Enum.HumanoidStateType.Running and Sprinting then
		if not SprintAnim.IsPlaying then
			SprintAnim:Play()
			SprintAnim:AdjustSpeed(1.1)
			
		end
	elseif new ~= Enum.HumanoidStateType.Running then
		if SprintAnim.IsPlaying then
			SprintAnim:Stop()
		end
	end
end)```