Animation not working when jumping

Solution found:
Fixed Script:

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()


local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=5628191355"

mouse.KeyDown:connect(function(key)
if key == "e" then
	if humanoid.Jump == false then
		humanoid.Parent.Animate.Disabled = true
		humanoid.Jump = true
		local playAnim = humanoid:LoadAnimation(anim)
		playAnim:Play()
		wait(playAnim.Length)
		humanoid.Parent.Animate.Disabled = false
	end
  end
end)

Hi! So, basically, I am trying to make acrobatic animations such as flips and stuff. I have currently finished my first animation and a keybind animation script. Yet it doesn’t work when you are in the air, and that’s essentially the point of it really baha. I’m assuming it’s because the fall animation is overriding the animation but I was wondering if there was anyway to cancel the fall animation?

This is the local script inside of StartPlayerScripts that plays the animation:

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()


local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=5628191355"

mouse.KeyDown:connect(function(key)
if key == "e" then
	if humanoid.Jump == false then
		humanoid.Jump = true
		local playAnim = humanoid:LoadAnimation(anim)
		playAnim:Play()
	end
  end
end)

Is there any way to cancel all animations before one animation is complete?

You have to use humanoid.Parent.Animate.Disabled = true and humanoid.Parent.Animate.Disabled = false to disable default animations while your using custom animations.

Heres your fixed script:

local player = game.Players.LocalPlayer
repeat wait() until player.Character.Humanoid
local humanoid = player.Character.Humanoid
local mouse = player:GetMouse()


local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/asset/?id=5628191355"

mouse.KeyDown:connect(function(key)
if key == "e" then
	if humanoid.Jump == false then
		humanoid.Parent.Animate.Disabled = true
		humanoid.Jump = true
		local playAnim = humanoid:LoadAnimation(anim)
		playAnim:Play()
		wait(playAnim.Length)
		humanoid.Parent.Animate.Disabled = false
	end
  end
end)
1 Like

The way you detect keypresses has essentially been deprecated in favor of using UserInputService and ContextActionService. You should consider checking them out.

Simple demonstration using UserInputService:

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(funnction(Key)
    if Key.KeyCode == Enum.KeyCode.E then
        --E was pressed!
    end
end)
1 Like

Thanks so so much!! <3
I appreciate this!
It worked too!

1 Like