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
.
1 | game:GetService( "UserInputService" ).InputBegan:connect( function (key,gameProcessedEvent) |
2 | if key.KeyCode = = Enum.KeyCode.Space then |
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:
01 | local Player = game.Players.LocalPlayer |
03 | while not Player.Character do |
07 | local character = Player.Character |
08 | local mouse = Player:GetMouse() |
09 | local humanoid = character:WaitForChild( "Humanoid" ) |
10 | local torso = character:WaitForChild( "Torso" ) |
11 | local head = character:WaitForChild( "Head" ) |
14 | game:GetService( "UserInputService" ).InputBegan:connect( function (key) |
15 | if key.KeyCode = = Enum.KeyCode.Space then |
16 | if humanoid.Jump = = true then |
17 | if debounce = = false then |
21 | local torso = character:FindFirstChild( "Torso" ) |
22 | torso.Velocity = Vector 3. new(torso.Velocity.X, humanoid.JumpPower * 1.7 , torso.Velocity.Z) |
24 | repeat wait() until humanoid.Jump = = false and humanoid:GetState() = = Enum.HumanoidStateType.Landed |
Also use 'tab' to format your code, not space.
Hope I helped :)
~TDP