Hello, I made a double jump system looking at youtube tutarials.
The problem is that I want to make it possible so only I can double jump and I am not excatly sure how it is done or where to put it. I know it has if and something but idk anything else.
Here is the code
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)```
Can I ask you one more thing pls? How can I make it so there is a command and then it enables it.
For examle I write ;djump in chat and then I can double jump and then if I write it again I can’t double jump?
You’d need a moderate understanding of string manipulation and Lua (the programming language Roblox uses)
Typically, you can’t expect people on here to write you up entire scripts or modified scripts, but I’m not saying it doesn’t happen.
I’d recommend digging into a tutorial series if you’re interested in developing on Roblox, it’s also a kickstart for if you desire to dig into more complex engines like Unity or maybe Unreal, so I’d say it’s definitely worth it. (I’ve only really fully learned Lua and it’s given me great insight on programming all together, and it all makes much more sense to me now than when I first started.)