Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I re-enable my jump?

Asked by
neoG457 315 Moderation Voter
8 years ago

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)

2 answers

Log in to vote
3
Answered by 8 years ago

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.

Ad
Log in to vote
0
Answered by
Cuvette 246 Moderation Voter
8 years ago
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

0
Is there another way other than this? neoG457 315 — 8y
0
Plenty of ways, you could change it through contact with a brick etc... Just make sure it's defined inside a funtion Cuvette 246 — 8y

Answer this question