Jump anim still when character stop jumping

Hi, I’m trying to make the running animation stop when the player is jumping.

This is what happens:

Here’s the code:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local camera = game.Workspace.CurrentCamera

local animFile = script:WaitForChild("RunAnim")
local animn = humanoid:LoadAnimation(animFile)

local UIS = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")

local Configuration = require(game.ReplicatedStorage:WaitForChild("Configuration"))

function IsWalking()
	if humanoid.MoveDirection.Magnitude > 0 then
		return true
	else
		return false
	end
end

UIS.InputBegan:Connect(function(key, gameprocess)
	if key.KeyCode == Configuration.RunKey then
		if IsWalking() then
			animn:Play()
			humanoid.WalkSpeed = Configuration.RunSpeed
			TweenService:Create(camera, TweenInfo.new(Configuration.TweenFovDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {FieldOfView = Configuration.RunFov}):Play()
		end
	end
end)

UIS.InputEnded:Connect(function(key, gameprocess)
	if key.KeyCode == Configuration.RunKey then
		animn:Stop()
		humanoid.WalkSpeed = Configuration.WalkSpeed
		TweenService:Create(camera, TweenInfo.new(Configuration.TweenFovDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {FieldOfView = Configuration.WalkFov}):Play()
	end
end)

local runService = game:GetService("RunService")

local function PlayerNotMoving()
	if humanoid.MoveDirection.Magnitude == 0 then
		animn:Stop()
		TweenService:Create(camera, TweenInfo.new(Configuration.TweenFovDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {FieldOfView = Configuration.WalkFov}):Play()
	end
end

runService.RenderStepped:Connect(PlayerNotMoving)

A few questions:

  • Why are you not implementing this animation into the default Animate script?
  • You should be using Vector3:FuzzyEq.

Anyways, I suggest adding the anim:stop() into the PlayerNotMoving function.

1 Like

I change the repository and the problem still

And how Vector3:FuzzyEq works, i don’t really know that.

I’m newbie, sorry.

I didn’t fix the problem yet.

Anyways, you can detect if the character is touching the ground by detecting the Humanoid.FloorMaterial and making sure it isn’t Air.

That was something i tried but you know the rest of the history, let me know when u fin the solution!

local function PlayerNotMoving()
	if humanoid.MoveDirection.Magnitude == 0 then
		animn:Stop()
		TweenService:Create(camera, TweenInfo.new(Configuration.TweenFovDuration, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {FieldOfView = Configuration.WalkFov}):Play()
	elseif humanoid.FloorMaterial == Enum.Material.Air then
        animn:Stop()
    end
end

Try this? I just did a check if the floor material is air and stopped an animation. There are better ways of doing this however this is mostly just a demonstration.

It works but not at all, when the player touch the floor again the animation stops and you need to press shift again to make it works again.

You could just give the jump animation a higher animation priority than the run animation.
Copy the animate script inside your character, past it in the starter character scripts and swap out the jump animation with the new 1 with a higher animation priority.

If you want to continue with the method you were doing, you need to define another code where it would be able to start up again after you’ve stopped. You cut off the animation when you did animn:Stop(), you’re going to need to restart it.

Here’s a update

I rewrite the entire code but there’s something that i don’t really understand.

Test code:

local function Run()
	if PlayerJumping() == false and script:WaitForChild("Running").Value == true then
		Anim:Play()
	elseif PlayerJumping() == true and script:WaitForChild("Running").Value == true then
		Anim:Stop()
	end
end

RunService.RenderStepped:Connect(Run)

Result: The result is as expected.

Code in the input fuction:

UserInput.InputBegan:Connect(function(input, gameprocess)
	if (not gameprocess) then
		if PlayerWalking() then
			if input.KeyCode == Enum.KeyCode.LeftShift then
				script.Running.Value = true
				Run()
				humanoid.WalkSpeed = RunSpeed
			end
		end
	end
end)

Result: Don’t know why works diferent.

Here’s the entire code:

local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local UserInput = game:GetService("UserInputService")

local RunService = game:GetService("RunService")

local NormalSpeed = 9
local RunSpeed = 24

local Camera = game.Workspace.CurrentCamera
local CameraVector = Camera.CFrame.LookVector

local Empujo = Instance.new("BodyVelocity")

local AnimFile = character:WaitForChild("Animate"):WaitForChild("run"):WaitForChild("RunAnim")
local Anim = humanoid:LoadAnimation(AnimFile)

local WalkFile = character:WaitForChild("Animate"):WaitForChild("walk"):WaitForChild("WalkAnim")
local WalkAnim = humanoid:LoadAnimation(WalkFile)



local function PlayerWalking()
	if humanoid.MoveDirection.Magnitude > 0 then
		return true
	else
		return false
	end
end

local function PlayerJumping()
	if humanoid.FloorMaterial == Enum.Material.Air then
		return true
	else
		return false
	end
end

local function Run()
	if PlayerJumping() == false and script:WaitForChild("Running").Value == true then
		Anim:Play()
	elseif PlayerJumping() == true and script:WaitForChild("Running").Value == true then
		Anim:Stop()
	end
end



UserInput.InputBegan:Connect(function(input, gameprocess)
	if (not gameprocess) then
		if PlayerWalking() then
			if input.KeyCode == Enum.KeyCode.LeftShift then
				script.Running.Value = true
				Run()
				humanoid.WalkSpeed = RunSpeed
			end
		end
	end
end)

UserInput.InputEnded:Connect(function(input, gameprocess)
	if (not gameprocess) then
		if input.KeyCode == Enum.KeyCode.LeftShift then
			script.Running.Value = false
			Anim:Stop()
			humanoid.WalkSpeed = NormalSpeed
		end
	end
end)

The jump animation priority is higher than the run and walk animation.

If you play an animation over and over before it can even finish, the animation won’t even play correctly.

I finally found a solution, it was putting the animation speed inside the animate script and it works perfectly.

Ty all for the help.

1 Like