Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I re-enable my jump?

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)

1 comment

2 answers

✓ Accepted answer

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

2 comments

0

Is there another way other than this?

0

Plenty of ways, you could change it through contact with a brick etc... Just make sure it's defined inside a funtion

This discussion is preserved as it was. New answers, comments, and votes are closed.