0% found this document useful (0 votes)
2K views1 page

Roblox Double Jump Script

This document defines code for enabling double jumping in a game. It sets up variables to track double jump state and stores the original jump power. On jump, it checks if a double jump is allowed and increases the jump power if so. On state changes, it resets double jump values appropriately.

Uploaded by

juan gomez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views1 page

Roblox Double Jump Script

This document defines code for enabling double jumping in a game. It sets up variables to track double jump state and stores the original jump power. On jump, it checks if a double jump is allowed and increases the jump power if so. On state changes, it resets double jump values appropriately.

Uploaded by

juan gomez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

local UserInputService = game:GetService("UserInputService")

local localPlayer = game.Players.LocalPlayer


local character
local humanoid

local canDoubleJump = false


local hasDoubleJumped = false
local oldPower
local TIME_BETWEEN_JUMPS = 0.2
local DOUBLE_JUMP_POWER_MULTIPLIER = 2

function onJumpRequest()
if not character or not humanoid or not character:IsDescendantOf(workspace)
or
humanoid:GetState() == Enum.HumanoidStateType.Dead then
return
end

if canDoubleJump and not hasDoubleJumped then


hasDoubleJumped = true
humanoid.JumpPower = oldPower * DOUBLE_JUMP_POWER_MULTIPLIER
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
end

local function characterAdded(newCharacter)


character = newCharacter
humanoid = newCharacter:WaitForChild("Humanoid")
hasDoubleJumped = false
canDoubleJump = false
oldPower = humanoid.JumpPower

humanoid.StateChanged:connect(function(old, new)
if new == Enum.HumanoidStateType.Landed then
canDoubleJump = false
hasDoubleJumped = false
humanoid.JumpPower = oldPower
elseif new == Enum.HumanoidStateType.Freefall then
wait(TIME_BETWEEN_JUMPS)
canDoubleJump = true
end
end)
end

if localPlayer.Character then
characterAdded(localPlayer.Character)
end

localPlayer.CharacterAdded:connect(characterAdded)
UserInputService.JumpRequest:connect(onJumpRequest)

You might also like