(urgent please) Running animation overriding jump and fall animation

Hey guys, when my running animation is playing, and the player is jumping or falling, then the jump or fall animations will not play at all. It will just continue to run as I press Shift, and I don’t know why. I’ve seen multiple posts with the same issue, and in the replies, people are saying it’s due to a priority problem, such as this one and that I just have to set the animation to priorities to movements. However, these solutions do not work at all for me, and they are few years old, so I don’t know if something changed. But if anyone knows a solution for this, I’d be really grateful.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer

local players = game:GetService("Players")

local function onCharacterAdded(character)
	local Hum = character:WaitForChild("Humanoid")
	local HRP = character:WaitForChild("HumanoidRootPart")

	local defaultWalkSpeed = 16
	local maxWalkSpeed = 25

	local defaultPlaybackSpeed = 1
	local maxPlaybackSpeed = 1.20

	Hum:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
		local walkSpeed = Hum.WalkSpeed

		local playbackSpeed = defaultPlaybackSpeed + (walkSpeed - defaultWalkSpeed) / (maxWalkSpeed - defaultWalkSpeed) * (maxPlaybackSpeed - defaultPlaybackSpeed)

		playbackSpeed = math.clamp(playbackSpeed, defaultPlaybackSpeed, maxPlaybackSpeed)

		HRP.Running.PlaybackSpeed = playbackSpeed
	end)
end

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		onCharacterAdded(character)
	end)
end)


local track
local isWalking = false

local function setCharacterSpeed(speed)
	local character = Player.Character
	if character then
		local humanoid = character:FindFirstChild("Humanoid")
		if humanoid then
			humanoid.WalkSpeed = speed
		end
	end
end

local function toggleRun(isRunning)
	local player = game.Players.LocalPlayer
	local character = player.Character
	if not character then
		return
	end

	local humanoid = character:FindFirstChild("Humanoid")
	if not humanoid then
		return
	end
	
	if humanoid:GetState() == Enum.HumanoidStateType.Seated then
		return
	end

	local runSpeed = 25 -- running speed
	if isRunning and isWalking then
		humanoid.WalkSpeed = runSpeed
		if not track then
			local character = Player.Character or Player.CharacterAdded:Wait()
			local humanoid = character:WaitForChild("Humanoid")
			local animator = humanoid:WaitForChild('Animator')

			local Animation = Instance.new("Animation")
			Animation.AnimationId = "rbxassetid://14849258471"
			Animation.Parent = script

			track = animator:LoadAnimation(Animation)
			
			track:Play()
			onCharacterAdded(character)
		end
	else
		humanoid.WalkSpeed = 16 -- default walk speed
		if track then
			track:Stop()
			track:Destroy()
			track = nil
		end
	end
end

local UserInputService = game:GetService("UserInputService")
local shiftHeld = false

local function checkShift(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		if gameProcessedEvent == false then
			shiftHeld = input.UserInputState == Enum.UserInputState.Begin
			toggleRun(shiftHeld)
		else
			shiftHeld = false
			toggleRun(false)
		end
	end
end

local movementKeys = {} -- store the state of movement keys (W, A, S, D)


local function checkWalk(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		shiftHeld = input.UserInputState == Enum.UserInputState.Begin
	elseif (input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.D) then
		movementKeys[input.KeyCode.Name] = input.UserInputState == Enum.UserInputState.Begin
	end

	local isAnyMovementKeyPressed = false

	for _, keyState in pairs(movementKeys) do
		if keyState then
			isAnyMovementKeyPressed = true
			break
		end
	end

	if shiftHeld and isAnyMovementKeyPressed then
		isWalking = true
		toggleRun(true)
		
	else
		isWalking = false
		toggleRun(false)
	end
	local character = Players.LocalPlayer.Character
	if character then
		onCharacterAdded(character)
	end
end

UserInputService.InputBegan:Connect(checkShift)
UserInputService.InputEnded:Connect(checkShift)
UserInputService.InputBegan:Connect(checkWalk)
UserInputService.InputEnded:Connect(checkWalk)

I know my script is not very well organised
I ALSO want to mention that by “jumping” and “falling” animations, im talking about ROBLOX default jump and running animations, not customized ones, my game only contains an animation for running and nothing else.

PLEASE check the replies

2 Likes

So what priority is your running anim right now? Have you tried setting the priority to movement through the script?

Hey! Alot happened since, so basically my anim was at movement priority, which i thought would fix it but it didnt, then i made it at core, and it finally worked, i have no clue why core works and not movement but it works now
One issue is that when i hit the ground after jumping the running animation won’t play again but ill try to fix that sooner or later, thanks for the reply anyway

1 Like

I will keep this post without a solution incase anyone knows how to fix the running animation not playing after hitting the ground but if i manage to find a solution by myself ill keep an update to it

update, tried to use humanoid:GetState() but it does not work, i tried debugging with print statements but nothing comes out, even in a new simple local script

wait(2)
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

if humanoid:GetState() == Enum.HumanoidStateType.Jumping or humanoid:GetState() == Enum.HumanoidStateType.FallingDown then
	print("Jumped! (or fell down)")
	while humanoid:GetState() ~= Enum.HumanoidStateType.Running do
		wait(0.1)
		print("Not running!")
	end
	print("running now!")
end