How can I make a leap/super jump ability?

Hi, I am a beginner scripter and I want to make a leaping ability available to only a certain team, and the other teams cannot leap.

I could not find any tutorial on how to make that.

Please help

2 Likes

You can just change the Humanoid.JumpPower to make a plr jump higher. If you want to make it look better, use Animations. For activating it with a Key, you can use UserInputService or if it should be a tool, you can use tool.Activated.
Links:
Humanoid.JumpHeight/Power - Humanoid | Documentation - Roblox Creator Hub
Animations - Using Animations | Documentation - Roblox Creator Hub
UIS - UserInputService | Documentation - Roblox Creator Hub
Tool.Activated - Tool | Documentation - Roblox Creator Hub

If you then have more questions about anything, please tell. Hope that helped

3 Likes

Is it possible to make it work with a keybind combination (pressing two keys at once, eg. Alt + Z)?

2 Likes

There are for sure ways to do so.
You could do UIS.InputBegan and in an if statement, check if both Enum.KeyCode.Alt/Z are pressed down. I dont know atm the exact name for the event, but sth like .IsKeyDown or sth. It is for sure listed in the UIS documentation

2 Likes

Alright, thank you for the help!

3 Likes

this should cover that… (tested)

--local script
local uis=game:GetService("UserInputService")
local altPressed=false

uis.InputBegan:Connect(function(input)
	if input.KeyCode==Enum.KeyCode.LeftAlt then altPressed=true
	elseif altPressed and input.KeyCode==Enum.KeyCode.Z then

		print("Triggered")

	end
end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode==Enum.KeyCode.LeftAlt then
		altPressed=false
	end
end)

Sorry the old post was just too sloppy for me. Makes me a bit mad I can’t add them together. I know they are just numbers relating to the key. Clearly Roblox has these set up differently. To me this is a crazy work around but it seems like the only way to really do two key combos.

2 Likes

Yeah, that works, I just tested, thank you

1 Like

Hello, hi again.

Update: so I tried making leaping, but, I cannot really figure out on how to make the player move forward and fly upward/jump at the same time when looking forward (or any other direction other than up or down).

local player = game.Players.LocalPlayer
local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")

local altPressed = false
local zPressed = false
local speed = 50 -- Adjust this value to change the speed of movement
local upwardSpeed = 10 -- Adjust this value to change the upward speed
local upwardThreshold = 0.7 -- Adjust this value to set the threshold for looking up
local cooldownTime = 0.95 -- Cooldown time in seconds
local onCooldown = false -- Tracks if the ability is on cooldown

-- Function to check if the player is looking up
local function isLookingUp()
	local camera = workspace.CurrentCamera
	local lookVector = camera.CFrame.LookVector
	return lookVector.Y > upwardThreshold
end

-- Function to check if the player is looking down
local function isLookingDown()
	local camera = workspace.CurrentCamera
	local lookVector = camera.CFrame.LookVector
	return lookVector.Y < -upwardThreshold
end

-- Function to move the player forward with upward velocity
local function moveForwardWithUpwardVelocity()
	local forwardVector = player.Character.HumanoidRootPart.CFrame.LookVector
	local upwardVelocity = Vector3.new(0, upwardSpeed, 0)
	player.Character.HumanoidRootPart.Velocity = (forwardVector * speed) + upwardVelocity
end

-- Function to handle cooldown
local function startCooldown()
	onCooldown = true
	wait(cooldownTime)
	onCooldown = false
end

-- Check for keybind combination
userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftAlt then
		altPressed = true
	elseif input.KeyCode == Enum.KeyCode.Z and not onCooldown then
		zPressed = true
		startCooldown()
	end
end)

userInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftAlt then
		altPressed = false
	elseif input.KeyCode == Enum.KeyCode.Z then
		zPressed = false
	end
end)

-- Continuous check for keybind combination and camera orientation
runService.RenderStepped:Connect(function()
	if altPressed and zPressed then
		if isLookingUp() then
			-- Move upward only if looking up
			player.Character.HumanoidRootPart.Velocity = Vector3.new(0, speed, 0)
		elseif not isLookingDown() then
			-- Move forward with upward velocity if not looking down
			moveForwardWithUpwardVelocity()
		else
			-- Move forward without upward velocity if looking down
			local forwardVector = player.Character.HumanoidRootPart.CFrame.LookVector
			player.Character.HumanoidRootPart.Velocity = forwardVector * speed
		end
	end
end)

Edit: forgot to add the symbols to not make the script look like a jumbled mess.

2 Likes

Why not just add to jump power while the keys are down. Then let the game physics take care of the rest.

2 Likes

I thought if I did that the player wouldn’t forcefully jump, sorry

2 Likes

No need to be sorry, but that is something I would surly test. Seems to me it is just what you’re looking for.

3 Likes

@2112Jay is right. If you have the player`s humanoid on the Server, you can just do:

local hum = plr.Character:WaitForChild("Humanoid")
hum.Jump = true

So you take your UIS part, and when true, you fire a RemoteEvent to the Server which fires this code

2 Likes

I used a LocalScript in StarterPlayerScripts to make the leaping ability, so do I need to rewrite the entire script from scratch, or I can reuse my current script and just modify it?

Edit: I misread the last part of your message by accident, woops…

2 Likes

Update: it works, the player now jumps and moves forward when leaping and looking forward, thanks guys!

2 Likes

Have to go to StarterPlayer and set CharacterUseJumpPower to true. Alt is messing with the interface so I went LeftControl. And we can skip the combo keys here by just using the jump key as is.

--local script
local player=game:GetService("Players").LocalPlayer
local humanoid=player.Character:WaitForChild("Humanoid")
local uis=game:GetService("UserInputService")

uis.InputBegan:Connect(function(input)
	if input.KeyCode==Enum.KeyCode.LeftControl then
		humanoid.JumpPower=120 
	end
end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode==Enum.KeyCode.LeftControl then
		humanoid.JumpPower=50
	end
end)

Basically you hold down LeftControl and you get more jump power.

3 Likes

Lol, I just scripted it rq for you. Well if you still need it:
LOCAL SCRIPT:

local player = game.Players.LocalPlayer
local userInputService = game:GetService("UserInputService")
local rep = game:GetService("ReplicatedStorage").RemoteEvent

local cooldownTime = 1
local onCooldown = false
local altPressed = false
local zPressed = false

local function startCooldown()
	onCooldown = true
	rep:FireServer()
	wait(cooldownTime)
	onCooldown = false
end

userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftControl then
		altPressed = true
	elseif input.KeyCode == Enum.KeyCode.Z and not onCooldown then
		zPressed = true
		startCooldown()
	end
end)

userInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftControl then
		altPressed = false
	elseif input.KeyCode == Enum.KeyCode.Z then
		zPressed = false
	end
end)

SERVER SCRIPT:

local rep = game:GetService("ReplicatedStorage").RemoteEvent

rep.OnServerEvent:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hum = char.Humanoid
	hum.JumpHeight += 100
	hum.Jump = true
end)

Now you only need to add an RemoteEvent in ReplicatedStorage and itll work
EDIT: I also used LeftControl

3 Likes

But will it replicate to the server?

2 Likes

Semi-unrelated question, but the LocalScript that I made, will it show the player actually leap on everyone else’s ends or will it only be on the end of the person who has leaped?

2 Likes

my version will be shown to every player and the server, which is why I made a RemoteEvent. But Im not too sure about your solution

1 Like

I tested with another person, and they said that it showed me leap, but just incase I will use your version xd, thanks again btw

2 Likes