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 make a custom jump key (and unbind the original one)???

Hello, I have done due diligence, googled, and searched the Developer Hub to no avail. I cannot figure out how to bind a new key to Jumping. I am NOT requesting you to script it for me. I am asking for an explanation of what I'd need to do to make the script myself.

2 answers

✓ Accepted answer

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:

local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")

ContextActionService:UnbindAction("jumpAction")

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.KeyCode == Enum.KeyCode.LeftControl and gameProcessedEvent then
		local character = game:GetService("Players").LocalPlayer.Character

		if character then
			if character.Humanoid.Health > 0 then
				character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			end
		end
	end
end)

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.

3 comments

0

How did you know the Jump Action was called jumpAction? Are there documentation of the default ROBLOX actions?

0

Also, do you unbind on the client or server?

0

Unbind it on the client. There's a BindedActions dropdown on the developer console and it tells you the name of all actions.

What I think that will work is use a body force or something like that and make it move the player upwards, then just set the jump power to 0. It is probably not the best way but it should work.

2 comments

0

This isn't really the answer I'm looking for, because I might apply the same principle to other things, such as walking, and I don't really want a hacky solution. This would probably work,though. There has to be a clean way to do it with the already-present jump function, right?

0

yea probs but im not that good with scripting so thats how i thought it would work lmao

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