Whats Wrong With My Script

What is wrong with my double jump script. I want it to be able to make a frontflip animation when the player double jumps.

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 = 2
local Animation = Instance.new("Animation")
Animation.Name = "DoubleJumpAnimation"
Animation.AnimationId = "rbxassetid://5936541478"
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 AnimationLooped = humanoid:LoadAnimation(Animation)
		AnimationLooped.Looped = false
		AnimationLooped:AdjustSpeed(0.25)
	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 think you forgot to play an animation or something :grimacing:

What about this part of the script?

Is there anywhere that says:

Animation:Play()

?

Oh forgot about that part!

I hate word limit

1 Like

Can I copy your script, I want to fly.

Yh sure you can go ahead and use it!

great, is it already fix ?
########

Just Add This :

local AnimationLooped = humanoid:LoadAnimation(Animation)
		AnimationLooped.Looped = false
		AnimationLooped:AdjustSpeed(0.25)
        AnimationLooped:Play()

Changed it up a little.

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.1
local DOUBLE_JUMP_POWER_MULTIPLIER = 2
local Animation = Instance.new("Animation")
Animation.Name = "DoubleJumpAnimation"
Animation.AnimationId = "rbxassetid://5936541478"
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 AnimationLooped = humanoid:LoadAnimation(Animation)
		AnimationLooped.Looped = false
		AnimationLooped:AdjustSpeed(0.25)
		AnimationLooped: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)

This part was changed. It was that the Connect was lowercase.

localPlayer.CharacterAdded:Connect(characterAdded)
UserInputService.JumpRequest:Connect(onJumpRequest)
1 Like

Anyone knows what happened? I need help!

what is wrong ?
###############

Another try!

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.1
local DOUBLE_JUMP_POWER_MULTIPLIER = 2
local Animation = Instance.new("Animation")
Animation.Name = "DoubleJumpAnimation"
Animation.AnimationId = "rbxassetid://5936541478"
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 AnimationTrack = humanoid:LoadAnimation(Animation)

local function animate()
	AnimationTrack:Play()
	AnimationTrack.Looped = false
	AnimationTrack:AdjustSpeed(0.25)
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, animate)

Whats wrong!

I just want to say, you need to use your own animation id if you did not own it. That’s all I can help.

Oh okay! Thanks for the help man!

I used my own animation but still doesn’t work!

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.1
local DOUBLE_JUMP_POWER_MULTIPLIER = 2
local Animation = Instance.new("Animation")
Animation.Name = "DoubleJAnimation"
Animation.AnimationId = "rbxassetid://7637267231"
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 AnimationTrack = humanoid:LoadAnimation(Animation)

local function animate()
	AnimationTrack.Looped = false
	AnimationTrack:AdjustSpeed(0.25)
	AnimationTrack:Play()
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, animate)

I used this video

I don’t know man, it’s complicated. The previous code work though. :thinking:

This should be on StarterCharacterScripts based on your error output.

Still nothing happened! It shows the same error!

Humanoid:LoadAnimation() is deprecated. Use Animator:LoadAnimation()

local animator = humanoid:FindFirstChildOfClass("Animator")
if animator then
	local animationTrack = animator:LoadAnimation(Animation)
	animationTrack:Play()
end

Also what’s the error you are getting?