This is the script for a double jump I have been writing. It works well, but because JumpRequest is called multiple times when jumping off the floor, it glitches out. Is there any way of fixing this?
local MAX_EXTRA_JUMPS = 4 -- 0 = Single jump; 1 = Double jump; etc
local BOOST_MULTI = 3.5
local TIME_BETWEEN_JUMPS = 0.15
local InputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local StateType = Enum.HumanoidStateType
local boostCount = 0
local oldHeight = Humanoid.JumpHeight
Humanoid.StateChanged:Connect(function(old, new)
if new ~= StateType.Landed then return end
boostCount = 0
end)
function OnJumpRequest()
print("Jumped")
if Humanoid:GetState() ~= StateType.Freefall then return end
if boostCount >= MAX_EXTRA_JUMPS then return end
boostCount += 1
Humanoid.JumpHeight *= BOOST_MULTI
wait()
Humanoid:ChangeState(StateType.Jumping)
wait()
Humanoid.JumpHeight /= BOOST_MULTI
print("Double Jumped")
end
InputService.JumpRequest:Connect(OnJumpRequest)
I haven’t tried debounce but I have used a cooldown between each jump. This fixes my problem but jumping off the ground. However, this feels unresponsive as you have to wait 0.2 seconds before you can double jump off the ground.
local MAX_EXTRA_JUMPS = 4 -- 0 = Single jump; 1 = Double jump; etc
local BOOST_MULTI = 5
local TIME_BETWEEN_JUMPS = 0.2
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local InputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local StateType = Enum.HumanoidStateType
local boostCount = 0
local oldHeight = Humanoid.JumpHeight
local currentTick = 0
local lastTick = 0
Humanoid.StateChanged:Connect(function(old, new)
if new ~= StateType.Landed or boostCount == 0 then return end
boostCount = 0
ReplicatedStorage.BindableEvents.CharacterEvents.SpawnDebris:Fire()
end)
function OnJumpRequest()
print("Jumped")
-- Cooldown between each jump --
lastTick = currentTick
currentTick = tick()
if tick() - lastTick < TIME_BETWEEN_JUMPS then return end
-- End --
if Humanoid:GetState() ~= StateType.Freefall then return end
if boostCount >= MAX_EXTRA_JUMPS then return end
boostCount += 1
Humanoid.JumpHeight *= BOOST_MULTI
wait()
Humanoid:ChangeState(StateType.Jumping)
wait()
Humanoid.JumpHeight /= BOOST_MULTI
print("Double Jumped")
end
InputService.JumpRequest:Connect(OnJumpRequest)
This would be a bit of work, but I suggest adapting this over to use UserInputService, that way you can detect when the spacebar is lifted with InputEnded.