EDIT:
It looks like you set up a boolean to handle this yourself. If you want to do it this way, make sure you define the variable “debounce” outside of the event.
local userInput = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local char = player.Character
player.CharacterAdded:Connect(function(c)
char = c
end)
local jumpEvent = script.Parent.Jumped
local animation = script:WaitForChild("Boost")
local anim = char.Humanoid:LoadAnimation(animation)
local upgradeEvent = script.Parent.Upgrade
local background = script.Parent.Background
local bar = background.Bar
local label = script.Parent.Label
local maxJumps = player.DJumps.MaxDJumps.Value
local jumpsLeft = maxJumps
local onGround = false
local debounce = false
coroutine.resume(coroutine.create(function()
while wait(.1) do
local ray = Ray.new(char.HumanoidRootPart.Position, Vector3.new(0,-3,0))
local hit,pos = workspace:FindPartOnRayWithIgnoreList(ray,{char})
if hit then
onGround = true
bar:TweenSize(UDim2.new(1,0,1,0),
Enum.EasingDirection.InOut,
Enum.EasingStyle.Quad,
.1
)
maxJumps = player.DJumps.MaxDJumps.Value
char.Humanoid.JumpPower = 50
script.Parent.Enabled = false
bar.Visible = true
jumpsLeft = maxJumps
label.Text = jumpsLeft.."/"..maxJumps
else
onGround = false
end
end
end))
upgradeEvent.Event:Connect(function(newValue)
maxJumps = newValue
end)
local db = 0
if db == 2 then
wait(3)
db = 0
else
jumpEvent.Event:Connect(function()
if onGround == false then
script.Parent.Enabled = true
end
if jumpsLeft > 0 and char and debounce == false then
db = db + 1
if onGround == false then
debounce = true
jumpsLeft -= 1
label.Text = jumpsLeft.."/"..maxJumps
char.Humanoid.JumpPower = 50
bar:TweenSize(UDim2.new(jumpsLeft / maxJumps,0,1,0),
Enum.EasingDirection.InOut,
Enum.EasingStyle.Quad,
.1
)
if jumpsLeft == 0 then
delay(.1, function()
bar.Visible = false
end)
end
char.Humanoid.JumpPower = 150
anim:Play()
char.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
delay(0.3, function()
end)
end
end
end)
userInput.JumpRequest:Connect(function()
jumpEvent:Fire()
end)
end
the problem is now when the player loads in it works and then when the player try to double it doesn’t work
Well you are not setting “debounce” back to false from what I can see. It looks like you removed that in the updated script. If it still double jumps by holding jump, would you mind placing a print(debounce) inside the event, just to double check?
local userInput = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
repeat wait() until player.Character
local char = player.Character
player.CharacterAdded:Connect(function(c)
char = c
end)
local jumpEvent = script.Parent.Jumped
local animation = script:WaitForChild("Boost")
local anim = char.Humanoid:LoadAnimation(animation)
local upgradeEvent = script.Parent.Upgrade
local background = script.Parent.Background
local bar = background.Bar
local label = script.Parent.Label
local maxJumps = player.DJumps.MaxDJumps.Value
local jumpsLeft = maxJumps
local onGround = false
local debounce = false
coroutine.resume(coroutine.create(function()
while wait(.1) do
local ray = Ray.new(char.HumanoidRootPart.Position, Vector3.new(0,-3,0))
local hit,pos = workspace:FindPartOnRayWithIgnoreList(ray,{char})
if hit then
onGround = true
bar:TweenSize(UDim2.new(1,0,1,0),
Enum.EasingDirection.InOut,
Enum.EasingStyle.Quad,
.1
)
maxJumps = player.DJumps.MaxDJumps.Value
char.Humanoid.JumpPower = 50
script.Parent.Enabled = false
bar.Visible = true
jumpsLeft = maxJumps
label.Text = jumpsLeft.."/"..maxJumps
else
onGround = false
end
end
end))
upgradeEvent.Event:Connect(function(newValue)
maxJumps = newValue
end)
jumpEvent.Event:Connect(function()
if onGround == false then
script.Parent.Enabled = true
end
if jumpsLeft > 0 and char and debounce == false then
if onGround == false then
debounce = true
jumpsLeft -= 1
label.Text = jumpsLeft.."/"..maxJumps
char.Humanoid.JumpPower = 50
bar:TweenSize(UDim2.new(jumpsLeft / maxJumps,0,1,0),
Enum.EasingDirection.InOut,
Enum.EasingStyle.Quad,
.1
)
if jumpsLeft == 0 then
delay(.1, function()
bar.Visible = false
end)
end
char.Humanoid.JumpPower = 150
anim:Play()
char.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
delay(0.3, function()
debounce = false
end)
end
end
end)
userInput.JumpRequest:Connect(function()
jumpEvent:Fire()
end)
Alright. If you place a print(debounce) inside of your event, what does it return? You also may want to check for the state change to falling, and set “debounce” to false when that occurs, instead of waiting for a set period of time: Humanoid.StateChanged (roblox.com).
EDIT:
You may be having an issue because of the script detecting when a player is on the ground. Try changing the Vector3 to Vector3.new(0, -4, 0). Add a wait(0.5) before onGround = false. Let me know if this fixes it.
I know that you did not want a script given to you, but if it is still not working you might cross reference your version of the script, with this one inside of StarterCharacterScripts (which works for me on a baseplate):
local userInput = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = script.Parent
local maxJumps = 1
local jumpsLeft = maxJumps
local onGround = true
local debounce = false
char.Humanoid.StateChanged:connect(function(Old, New)
if New == Enum.HumanoidStateType.Landed then
onGround = true
char.Humanoid.JumpPower = 50
jumpsLeft = maxJumps
elseif (New == Enum.HumanoidStateType.Jumping) or (New == Enum.HumanoidStateType.Freefall) then
print("Changed")
wait(0.3)
onGround = false
end
end)
function jumpEvent()
if onGround == false then
else
end
if (jumpsLeft > 0) and (char) and (debounce == false) then
print("JumpsLeft:"..jumpsLeft.." debounce:"..tostring(debounce))
if onGround == false then
debounce = true
jumpsLeft -= 1
char.Humanoid.JumpPower = 150
char.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
print("DOUBLE")
wait(0.3)
print(debounce)
debounce = false
end
end
end
userInput.JumpRequest:Connect(function()
jumpEvent()
end)