Double Jump Ability Fires Instantly

Im trying to make a double jump script, but it fires when the person jumps the first time not the second time. Is there a way for you to check when the person jumps a second time and is freefalling? Thanks for the help!

Here is the script:



local UserInputService = game:GetService("UserInputService")
local localPlayer = game.Players.LocalPlayer
local character
local humanoid
 
local canDoubleJump = false
local hasDoubleJumped = false
local DOUBLE_JUMP_POWER_MULTIPLIER = 1.5

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
		if  localPlayer.folder.Doublejump.Value == false then
			return
		end

	if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
			hasDoubleJumped = true
			humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER		
			humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			local idk = game.ReplicatedStorage.Poof:Clone()
			idk.Position = character.HumanoidRootPart.Position
			idk.Parent = workspace
			task.wait(0.5)
			idk:Destroy()
			local value = 0

			while true do
				wait(0.1)
				game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Visible = true
				value += 0.1
				game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Position += UDim2.new(0,0,0.01,0)
				game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.TextLabel.Visible =  true

				local newvalue =  math.round(value / 100) * 100
				game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.TextLabel.Text = string.format("%0.1f", 10 - value)
				if game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Position.Y.Scale >= 1   then
					game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Visible = false
					game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Position = UDim2.new(0,0,0,0)
					game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.TextLabel.Visible =  false
					break
				end
			end	

		end
	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 
			if  localPlayer.folder.Doublejump.Value == false then return end
			game.ReplicatedStorage.Abilites.Jump2:FireServer()
			canDoubleJump = false
			hasDoubleJumped = false
			humanoid.JumpPower = oldPower

			
		elseif new == Enum.HumanoidStateType.Freefall then
			canDoubleJump = true
		end
	end)
end
 
if localPlayer.Character then
	characterAdded(localPlayer.Character)
end
 
localPlayer.CharacterAdded:connect(characterAdded)
UserInputService.JumpRequest:connect(onJumpRequest)


Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

you only referencing the oldPower when the character is added, try putting it at the top of the script.

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

local canDoubleJump = false
local hasDoubleJumped = false
local DOUBLE_JUMP_POWER_MULTIPLIER = 1.5
local oldPower -- here

Its still doing the same problem, should I remove the old power from when the player joined? I highly dought that this is the problem though.

I think you should also define humanoid and character outside the characterAdded too

Make a value for how much they have jumped and set it to 0, then add 1 when they jumped the first time, check if they are free falling and the value is 1, then do another jump, if they touched the ground then reset the value, if the number is 2 or higher then don’t jump.

how would I checked if they jumped, because the humanoidstatetype.jumping only adds the number when they touch the ground and jump again.

1 Like

I guess use userInputService and Check if they are free falling.

I went into studio a made a quick script:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid")

Humanoid.Jumping:Connect(function(active)
	if active == true then
		print("Jumped")
	end
end)

this one checks as soon as the request is sent.

This is what I did, whenever I print jumpamt it goes, 2,3,1. 1 is addewd when it lands. Here is the script

local function characterAdded(newCharacter)
	character = newCharacter
	humanoid = newCharacter:WaitForChild("Humanoid")
	hasDoubleJumped = false
	canDoubleJump = false
	humanoid.StateChanged:connect(function(old, new)
		if new == Enum.HumanoidStateType.Landed then 
			jumpamt = 0
			if  localPlayer.folder.Doublejump.Value == false then return end
			game.ReplicatedStorage.Abilites.Jump2:FireServer()
			canDoubleJump = false
			hasDoubleJumped = false
			humanoid.JumpPower = oldPower
		end
		if humanoid.Jumping then
			jumpamt += 1
			print(jumpamt)
		end
	end)
end
 

Sorry for the late reply, I was just working on your problem, anyway, I came up with this, it just makes a part under you and destroys it when you touch it, you can tinker it to your liking. I used the Jumping function and a stateChanged for checking. Read over it and tweak it to your liking.

--Player Variables
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid")

--Settings
local jumps = 0
local MAX_JUMPS = 2

local cooldown = 2

local touchingplatform = false

-- Jumping function
Humanoid.Jumping:Connect(function(active)
	if active == true and jumps < MAX_JUMPS then -- if is jumping and the jumping value doesnt exceed MAX_JUMPS
		jumps += 1-- add 1 to jumps
		
		if jumps < MAX_JUMPS then -- if jumps is less than MAX_JUMPS
			local Platform = Instance.new("Part", workspace) -- make new platform
			-- settings
			Platform.Transparency = 1
			Platform.Size = Vector3.new(15,1,15)
			Platform.Position = Character.PrimaryPart.Position+Vector3.new(0,-0.5,0)
			Platform.Anchored = true
			Platform.Name = "Platform"
			
			
			local db = false-- debounce

			local connection = Platform.Touched:Connect(function(otherpart)-- connect touched event
				if otherpart.Parent == Character and not db then--if touched by character and db is not true then
					db = true-- set debounce
					touchingplatform = true--touching platform
					task.wait(cooldown)--wait cooldown
					db = false-- set debounce
					touchingplatform = false--not touching platform
				end
			end)
			--cleanup
			game.Debris:AddItem(Platform, 0.5)
			task.wait(0.5)
			connection:Disconnect()
		end
		end
end)

Humanoid.StateChanged:Connect(function(old, new)-- check state
	if new == Enum.HumanoidStateType.Landed and touchingplatform == false then -- if landed and isnt touching platform
		jumps = 0--reset jumps
	end
end)


1 Like

I dont know if this is my part of the script but it is not double jumping here is the one that is makeyou hump higher:

function onJumpRequest()
	if not character or not humanoid or not character:IsDescendantOf(workspace) or
	 humanoid:GetState() == Enum.HumanoidStateType.Dead then
		return
	end
	print("east")
	if canDoubleJump and not hasDoubleJumped then
		if  localPlayer.folder.Doublejump.Value == false then
			return
		end
		print(jumps)
		if humanoid:GetState() == Enum.HumanoidStateType.Freefall and jumps == 2 then
			hasDoubleJumped = true
			humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER		
			humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			local idk = game.ReplicatedStorage.Poof:Clone()
			idk.Position = character.HumanoidRootPart.Position
			idk.Parent = workspace
			task.wait(0.5)
			idk:Destroy()
			local value = 0

			while true do
				wait(0.1)
				game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Visible = true
				value += 0.1
				game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Position += UDim2.new(0,0,0.01,0)
				game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.TextLabel.Visible =  true

				local newvalue =  math.round(value / 100) * 100
				game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.TextLabel.Text = string.format("%0.1f", 10 - value)
				if game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Position.Y.Scale >= 1   then
					game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Visible = false
					game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.Frame.Position = UDim2.new(0,0,0,0)
					game.Players.LocalPlayer.PlayerGui.Stuff.Ability.Jump.CanvasGroup.TextLabel.Visible =  false
					break
				end
			end	

		end
	end
end

Does anyone know how to fix this problem?