Double Jump With animation not working

I made a double Jump script and I tryed to make animations for it but it won’t work I tried to modify the script so everytime your double jump your are suppost to flip

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.2
local DOUBLE_JUMP_POWER_MULTIPLIER = 1
local anim = humanoid:LoadAnimation(script:FindFirstChildOfClass("Animation"))

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)
		
	end
end
 
local function characterAdded(newCharacter)
	character = newCharacter
	humanoid = newCharacter:WaitForChild("Humanoid")
	hasDoubleJumped = false
	canDoubleJump = false
	oldPower = humanoid.JumpPower
	anim.Looped = false
	anim:Play()
	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)

I got the animation

1 Like

EgoMoose has a open sourced game that has double jump and other stuff.
game: Platformer movement - Roblox

2 Likes

i can’t find what i want I need double jump with an animation in it

characterAdded only fires when the character is added in the game

i modified your code:

local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character = localPlayer.Character
local humanoid = character.Humanoid
 
local canDoubleJump = false
local hasDoubleJumped = false
local oldPower
local TIME_BETWEEN_JUMPS = 0.2
local DOUBLE_JUMP_POWER_MULTIPLIER = 1
local anim = humanoid:LoadAnimation(script:FindFirstChildOfClass("Animation"))

UserInputService.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.Space then
			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)
				anim.Looped = false
				anim:Play()
			end
		end
	end
end)

local function characterAdded(newCharacter)
	hasDoubleJumped = false
	canDoubleJump = false
	anim.Looped = 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)

it doesnt work it said that the humanoid needs the animation

did you make local character and local humanoid nil?

I have no idea :expressionless:

if you make the 2 variable nil, it will not work? Can i see what the error says?

Try this:

local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer

local character
local humanoid

local oldPower
 
local canDoubleJump = false
local hasDoubleJumped = false

local TIME_BETWEEN_JUMPS = 0.2
local DOUBLE_JUMP_POWER_MULTIPLIER = 1

local Animation = script:FindFirstChildOfClass("Animation");

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)
		
		local AnimationLoaded = humanoid:LoadAnimation(Animation);
		AnimationLoaded.Looped = false;
		AnimationLoaded:Play();
	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)

I got my animation in the local script don’t work still
image

can we see the error? or the animation is the same as the normal jump animation.

Its suppost to be a flip animationimage

change this code local Animation = script:FindFirstChildOfClass("Animation"); to local Animation = humanoid:LoadAnimation(script:FindFirstChildOfClass("Animation"))


now its this

can we see how the animation works?


This is the animation so when someone double jumps then they do this animation

use my code that i give to you

and test it again
(3030303030303030)

image same error