Double Jump Animation Error

Hello,
So you are probably going to be disappointed in me for saying that I free modeled a double jump script, which is understandable. I tested it out and it actually worked quite well, so I decided I would try to spice it up by changing the numbers around and adding sound and an animation for the second jump (a front flip).
Things went badly after the sound and number change and after trying many different things for about half an hour, I still couldn’t get past an error that prevented me from loading the animation in the humanoid, and therefore it couldn’t play. The error said, “attempted to locate a nil value.” I am completely lost with this script. How can I load the animation to the humanoid?

local UserInputService = game:GetService("UserInputService")

local localPlayer = game.Players.LocalPlayer

local character

local humanoid

local canDoubleJump = false

local hasDoubleJumped = false

local oldPower

local TIME_BETWEEN_JUMPS = 0.15

local DOUBLE_JUMP_POWER_MULTIPLIER = 1.6

function onJumpRequest()

if not character or not humanoid or not character:IsDescendantOf(workspace) or

humanoid:GetState() == Enum.HumanoidStateType.Dead then

return

end

if canDoubleJump and not hasDoubleJumped then

hasDoubleJumped = true

humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER

humanoid:ChangeState(Enum.HumanoidStateType.Jumping)

script.Woosh:Play()

--animation:Play() goes here, but how am i supposed to load it??

end

end

local function characterAdded(newCharacter)

character = newCharacter

humanoid = newCharacter:WaitForChild("Humanoid")

hasDoubleJumped = false

canDoubleJump = false

oldPower = humanoid.JumpPower

humanoid.StateChanged:connect(function(old, new)

if new == Enum.HumanoidStateType.Landed then

canDoubleJump = false

hasDoubleJumped = false

humanoid.JumpPower = oldPower

elseif new == Enum.HumanoidStateType.Freefall then

wait(TIME_BETWEEN_JUMPS)

canDoubleJump = true

end

end)

end

if localPlayer.Character then

characterAdded(localPlayer.Character)

end

localPlayer.CharacterAdded:connect(characterAdded)

UserInputService.JumpRequest:connect(onJumpRequest)

Thanks!

1 Like

Please screenshot the error
30char

You can use Humanoid:LoadAnimation() if thats what youre looking for.

local AnimObj = Instance.new("Animation")
AnimObj.AnimationId = "AnimationIDHere"

local animation = humanoid:LoadAnimation(AnimObj)
animation:Play()

the error was a result of some code that I added, but I don’t think I did it right (i’m pretty bad at scripting). My goal was to load the animation, how can I do that, given the stuff above?

I have no idea how, but it now works. Thanks for your help.

2 Likes