Hello there.
You must use ContextActionService. It is used for binding actions to keys.
You can first unbind the jump action by using ContextActionService:UnbindAction("jumpAction").
Then, you can use UserInputService to detect the input when the player jumped.
Example Code:
01 | local UserInputService = game:GetService( "UserInputService" ) |
02 | local ContextActionService = game:GetService( "ContextActionService" ) |
04 | ContextActionService:UnbindAction( "jumpAction" ) |
06 | UserInputService.InputBegan:Connect( function (input, gameProcessedEvent) |
07 | if input.KeyCode = = Enum.KeyCode.LeftControl and gameProcessedEvent then |
08 | local character = game:GetService( "Players" ).LocalPlayer.Character |
11 | if character.Humanoid.Health > 0 then |
12 | character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping) |
How it Works
You must first unbind the "jumpAction" action. Then, you must use the InputBegan
event of UserInputService to detect when the client makes an action. Next, you must check if the KeyCode is the KeyCode you want and that the player isn't in chat. I used LeftControl
as the jump key. Then, you must check if the character isn't nil and if the character's health is above 0. If it is, the humanoid will then jump.
Please accept this answer if it helped.