Jump animation plays only when u are running

Hello all, recently I’ve made this run script and another guy helped me with something, but I’m stuck on this topic.

How would i be able to make a jump animation, but it only activates when your running?

Source Code if you need it.

local uis = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local run = TweenService:Create(workspace.CurrentCamera, (TweenInfo.new)(0.5), {FieldOfView = 80})
local walk = TweenService:Create(workspace.CurrentCamera, (TweenInfo.new)(0.5), {FieldOfView = 70})
local playersHumanoid = game.Players.LocalPlayer.Character.Humanoid
--- Animation Creation
local newAnimation = (Instance.new)("Animation")
newAnimation.AnimationId = "rbxassetid://" .. script:GetAttribute("AnimationID")
loadAnimation = playersHumanoid:LoadAnimation(newAnimation)

-- Walkspeed Changing
local runSpeed = 25
local walkSpeed = 16
-- Variable 
local PlayerIsRunning = false
(uis.InputBegan):Connect(function(Key)

	if Key.KeyCode == (Enum.KeyCode).LeftShift then
		run:Play()
		loadAnimation:Play()

		playersHumanoid.WalkSpeed = runSpeed
		PlayerIsRunning = true
	end
end)

uis.InputEnded:Connect(function(Key)

	if Key.KeyCode == (Enum.KeyCode).LeftShift then
		walk:Play()
		loadAnimation:Stop()

		playersHumanoid.WalkSpeed = walkSpeed
		PlayerIsRunning = false
	end
end)

playersHumanoid.Changed:Connect(function()
	if playersHumanoid.Jump and loadAnimation.IsPlaying then
		loadAnimation:Stop()
	end
end)

playersHumanoid.StateChanged:Connect(function(oldState, newState)
	if newState == (Enum.HumanoidStateType).Landed and PlayerIsRunning then
		loadAnimation:Play()
	end
end)

Don’t mind some of the code, i felt bored and used some dumb decompile website

You should use the animation’s weight property. Set it to a higher value than the default so that when a player walks, the animation starts. Or, a lower value so it plays when you’re idle.

More information here:

Sorry for the deleted posts. :slight_smile:

playersHumanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Landed and PlayerIsRunning then
		loadAnimation:Play() -- Plays Run animation after a jump, if player is running.
	elseif newState == Enum.HumanoidStateType.Jump and PlayerIsRunning then
		loadRunJumpAnimation:Play() -- Plays Jump animation that will only appear in a jump, when the player is also running
	end
end) 

Hey again! Thanks, I’ll go test out, I just woke up.


gives an error for when i jump while running

It should be “Jumping”, not “Jump”.

This is what happens.


There are no errors coming from the output.

Make the “loadrunjump” animation have a higher priority. If you’re using Moon Animator, it should be in “Animation Settings”, if Roblox’s default animator, it’s in the File menu.

File menu? i never heard of that.
Ah, nevermind. You mean Action 1, 2, 3 Etc?

Yeah
image

It still happens for some reason. Is it the animation or script?

Did you publish the animation? You have to overwrite (publish to the same animation you were using) for this to work.

Yes, I did publish & overwrite it.

What even is loadRunJump? Did you put the ID properly in that animation?

Basically, it’s a second jump that only activates when you are running. Like sonic he only does the ball run while hes running

I don’t think you’ve read my reply correctly. What I was asking for is if you put the ID properly in that animation. An updated code snippet would help.

Yes, i did put it correctly. Here’s an updated code

local uis = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local run = TweenService:Create(workspace.CurrentCamera, (TweenInfo.new)(0.5), {FieldOfView = 80})
local walk = TweenService:Create(workspace.CurrentCamera, (TweenInfo.new)(0.5), {FieldOfView = 70})
local playersHumanoid = game.Players.LocalPlayer.Character.Humanoid
--- Animation Creation
local newAnimation = (Instance.new)("Animation")
newAnimation.AnimationId = "rbxassetid://" .. script:GetAttribute("AnimationID")
loadAnimation = playersHumanoid:LoadAnimation(newAnimation)

local runJumpAnim = (Instance.new)("Animation")
runJumpAnim.AnimationId = "rbxassetid://" .. script:GetAttribute("JumpID")
loadRunJump = playersHumanoid:LoadAnimation(newAnimation)
-- Walkspeed Changing
local runSpeed = 25
local walkSpeed = 16
-- Variable 
local PlayerIsRunning = false
(uis.InputBegan):Connect(function(Key)

	if Key.KeyCode == (Enum.KeyCode).LeftShift then
		run:Play()
		loadAnimation:Play()

		playersHumanoid.WalkSpeed = runSpeed
		PlayerIsRunning = true
		
	end
end)

uis.InputEnded:Connect(function(Key)

	if Key.KeyCode == (Enum.KeyCode).LeftShift then
		walk:Play()
		loadAnimation:Stop()

		playersHumanoid.WalkSpeed = walkSpeed
		PlayerIsRunning = false
	end
end)

playersHumanoid.Changed:Connect(function()
	if playersHumanoid.Jump and loadAnimation.IsPlaying then
		loadAnimation:Stop()
	end
end)

playersHumanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Landed and PlayerIsRunning then
		loadAnimation:Play()
	elseif newState == Enum.HumanoidStateType.Jumping and PlayerIsRunning then
		loadRunJump:Play()
	end
end)

looks exactly the same tho lol

Well, I’m not sure how to fix it. Maybe try adding a

loadAnimation:Stop()

after

loadRunJump:Play()

?

Didn’t Work but it’s fine. Thanks for helping though, much appreciated

One more question. when the player stops walking and you’re still holding the shift button, the animation continues to play. Any info on that?
and when the player isn’t walking and u hold shift it plays.