The script below successfully disables the jump when the key "b" is held down however I'm trying to re-enable it when the key is released but it's failing to work.
There are no errors given in the output, please help.
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() enabled = true Mouse.KeyDown:connect(function(key) if not enabled then return end if key == "b" then enabled = false Player.Character.Humanoid.Changed:connect(function() Player.Character.Humanoid.Jump = false end) Mouse.KeyUp:connect(function(key) if key == "b" then Player.Character.Humanoid.Jump = true end end) end enabled = true end)
All we really need the events for in this case would be for toggling our debounce variable.
local Player = game:GetService'Players'.LocalPlayer local Mouse = Player:GetMouse() local Char = Player.Character or Player.CharacterAdded:wait() local Human = Char:WaitForChild'Humanoid' local JumpEnabled = true -- Disable debounce Mouse.KeyDown:connect(function(key) if key:lower() == "b" then JumpEnabled = false end end) -- Enable debounce Mouse.KeyUp:connect(function(key) if key:lower() == "b" then JumpEnabled = true end end) -- Logic Human.Changed:connect(function(p) if p == "Jump" and not JumpEnabled then Human.Jump = false end end)
Explanation
Basically all we're doing is using the key events to toggle the JumpEnabled variable, and depending on what state it's in (true or false), it will decide whether or not to allow the character to jump when the humanoid changes.
Player.Character.Humanoid.Changed:connect(function() Player.Character.Humanoid.Jump = false wait(2) Player.Character.Humanoid.Jump = true end)
Try placing it inside the function like that