Jump animation cancels out run animation

Currently, I have a script that when you press shift it makes your walkspeed faster and it plays a animation, but the problem is that when I jump, it cancels out the sprint animation when I land, and it turns back into the normal walking animation. Here’s a visual representation.


I’m using custom animations, and the default roblox animation script
image
And this is the sprint script.

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer

UserInputService.InputBegan:Connect(function(input, gameProccesed)
	if gameProccesed then
		return
	else
		if input.KeyCode == Enum.KeyCode.LeftShift then
			humanoid = localPlayer.Character:WaitForChild("Humanoid")
			humanoid.WalkSpeed = 30
			
			local animation = Instance.new("Animation")
			animation.AnimationId = "rbxassetid://6828838446"
			animation.Parent = humanoid
			
			loadedAnimation = humanoid:LoadAnimation(animation)
			loadedAnimation:Play()
		end
	end
end)

UserInputService.InputEnded:Connect(function(input, gameProccesed)
	if gameProccesed then
		return
	else
		if input.KeyCode == Enum.KeyCode.LeftShift then
			humanoid.WalkSpeed = 16
			loadedAnimation:Stop()
		end
	end
end)

Is there any way to fix this bug?

1 Like

This is not a bug, Once you jump the run animation will stop and the jump animation will play.

I’m not sure what your point is

After the character stops jumping and falls onto the ground, instead of resuming the run animation as normal it plays the walk animation although the character is still running

3 Likes

change the priorities of the animations around, make the run animation have a higher priority than the walk animation. You can change this when exporting the animation to roblox, its in the explorer

1 Like

image
You can try something like this or changing it in the animation editor

	local Character = workspace:WaitForChild(Player.Name)
		local Humanoid = Character:WaitForChild('Humanoid')
		
local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = 'rbxassetid://507767714'
RAnimation = Humanoid:LoadAnimation(RunAnimation)

Running = false

function Handler(BindName, InputState)
	if InputState == Enum.UserInputState.Begin and BindName == 'RunBind' then
		Running = true
		Humanoid.WalkSpeed = 50
	elseif InputState == Enum.UserInputState.End and BindName == 'RunBind' then
		Running = false
		if RAnimation.IsPlaying then
			RAnimation:Stop()
		end
		Humanoid.WalkSpeed = 16
	end
end

Humanoid.Running:connect(function(Speed)
	if Speed >= 10 and Running and not RAnimation.IsPlaying then
		RAnimation:Play()
		Humanoid.WalkSpeed = 50
	elseif Speed >= 10 and not Running and RAnimation.IsPlaying then
		RAnimation:Stop()
		Humanoid.WalkSpeed = 16
	elseif Speed < 10 and RAnimation.IsPlaying then
		RAnimation:Stop()
		Humanoid.WalkSpeed = 16
	end
end)

Humanoid.Changed:connect(function()
	if Humanoid.Jump and RAnimation.IsPlaying then
		RAnimation:Stop()
	end
end)

game:GetService('ContextActionService'):BindAction('RunBind', Handler, true, Enum.KeyCode.LeftShift)```

what if we wanted to keep the default jumping animation?