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

Why does this Double Jump fail sometimes?

Asked by 9 years ago

This double jump script I made works however it sometimes fails to double jump and occasionally breaks completely, it's becoming really annoying and I can't pinpoint where the error is because there's nothing in the output.

I was hoping someone else could help me...Heres the script:

01local Player = game.Players.LocalPlayer
02 
03while not Player.Character do
04    wait()
05end
06 
07local character = Player.Character
08local mouse = Player:GetMouse()
09local humanoid = character:WaitForChild("Humanoid")
10local torso = character:WaitForChild("Torso")
11local head = character:WaitForChild("Head")
12local debounce = true
13 
14mouse.KeyDown:connect(function(key)
15    if key:byte() == 32 then                                                           
View all 33 lines...

Thank you for your time.

0
repeat wait() until humanoid.Jump == false and humanoid:GetState() == Enum.HumanoidStateType.Landed(source of error) and look at where your end statement for the inner if statement. scottmike0 40 — 9y
0
KeyDown is deprecated. That may be why it won't work. TheDeadlyPanther 2460 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

I'm not entirely sure what is wrong with your code, but here is basically the only improvement that could fix this problem;


UserInputService > KeyDown

KeyDown is deprecated, so it can be removed at any time. It may also not work properly sometimes. Instead, you should use UserInputService.

1game:GetService("UserInputService").InputBegan:connect(function(key,gameProcessedEvent)
2    if key.KeyCode == Enum.KeyCode.Space then -- it might be SpaceBar or something, I don't have access to KeyCodes at the moment
3        -- code
4    end
5end)

It is very similar to KeyDown, just that the returned key is not a string, but an Object with a property of 'KeyCode', and a second parameter - whether the game processed an event (like when a player is typing, so they don't jump when they press space)


If you're still confused, let me compile the code into your new script:

01local Player = game.Players.LocalPlayer
02 
03while not Player.Character do
04    wait()
05end
06 
07local character = Player.Character
08local mouse = Player:GetMouse()
09local humanoid = character:WaitForChild("Humanoid")
10local torso = character:WaitForChild("Torso")
11local head = character:WaitForChild("Head")
12local debounce = true
13 
14game:GetService("UserInputService").InputBegan:connect(function(key)
15    if key.KeyCode == Enum.KeyCode.Space then                                                           
View all 27 lines...

Also use 'tab' to format your code, not space.

Hope I helped :)

~TDP

0
Thanks for the detailed explanation too! SHDrivingMeNuts 299 — 9y
Ad

Answer this question