Skinstashery
Roblox
Home / Roblox / Studio script library / Double jump
RB-004

Roblox double jump script

Press jump again in mid-air for a second jump.

Script type
LocalScript
Where it goes
StarterPlayer > StarterPlayerScripts
Category
Movement

For your own game in Roblox Studio. Not for use in other people's games.

The code

-- Double jump: press Jump again while in the air.

local MAX_JUMPS = 2          -- 2 = one extra jump in the air. 3 = triple jump.

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

local player = Players.LocalPlayer

local humanoid = nil
local airJumpsUsed = 0

local function onCharacterAdded(character)
	humanoid = character:WaitForChild("Humanoid")
	airJumpsUsed = 0

	humanoid.StateChanged:Connect(function(_, newState)
		-- Touching the ground gives the extra jumps back.
		if newState == Enum.HumanoidStateType.Landed
			or newState == Enum.HumanoidStateType.Running then
			airJumpsUsed = 0
		end
	end)
end

player.CharacterAdded:Connect(onCharacterAdded)
if player.Character then
	onCharacterAdded(player.Character)
end

UserInputService.JumpRequest:Connect(function()
	if not humanoid or humanoid.Health <= 0 then
		return
	end

	local state = humanoid:GetState()
	if state == Enum.HumanoidStateType.Freefall and airJumpsUsed < MAX_JUMPS - 1 then
		airJumpsUsed += 1
		humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
	end
end)

How to set it up

  1. Open StarterPlayer, then StarterPlayerScripts, in the Explorer.
  2. Add a LocalScript there.
  3. Paste the code.
  4. Play, jump, and press Space again in the air.

Change it

More in Movement

All Roblox scripts

More Roblox tools