local UserInputService = game:GetService("UserInputService")
local Humanoid = script.Parent:WaitForChild("Humanoid")
local Debounce = false
local CanDoubleJump = false
local DoubleJumped = false
local function JumpRequest()
if Debounce then
Debounce = false
if CanDoubleJump and not DoubleJumped then
DoubleJumped = true
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
task.wait(.2)
Debounce = true
end
end
UserInputService.JumpRequest:Connect(JumpRequest)
local function StateChanged(i, v)
if v == Enum.HumanoidStateType.Landed then
CanDoubleJump = false
DoubleJumped = false
elseif v == Enum.HumanoidStateType.Freefall and DoubleJumped == false then
CanDoubleJump = true
DoubleJumped = false
end
end
Humanoid.StateChanged:Connect(StateChanged)
The script you provided has a few issues that need to be addressed:
Debounce should initially be set to true because it’s supposed to allow the first jump without any delay.
The debounce mechanism in the JumpRequest function should be improved to prevent multiple executions of the function within a short time frame.
The StateChanged function should have proper state management to reset the jump states correctly.
Here’s the revised script with the necessary fixes::
local UserInputService = game:GetService(“UserInputService”)
local Humanoid = script.Parent:WaitForChild(“Humanoid”)
local Debounce = true – Debounce should initially be true to allow the first jump
local CanDoubleJump = false
local DoubleJumped = false
local function JumpRequest()
if Debounce then
Debounce = false
if CanDoubleJump and not DoubleJumped then
DoubleJumped = true
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
-- Set a short delay before allowing the next jump request
task.wait(0.2)
Debounce = true
end
end
UserInputService.JumpRequest:Connect(JumpRequest)
local function StateChanged(_, newState)
if newState == Enum.HumanoidStateType.Landed then
CanDoubleJump = false
DoubleJumped = false
elseif newState == Enum.HumanoidStateType.Freefall and not DoubleJumped then
CanDoubleJump = true
DoubleJumped = false
end
end
Humanoid.StateChanged:Connect(StateChanged)
Changes made:
Initialized Debounce to true to allow the first jump.
Added a short delay (task.wait(0.2)) inside the JumpRequest function to handle debouncing correctly.
Simplified the condition checks and ensured the states are properly managed in the StateChanged function.
This should fix the issues and ensure that the double jump functionality works as expected.