Making A double Jump

So I’m trying to make a platformer that when you press “W” you will jump or If you’re pressing it twice it will jump twice, the thing is it infinitly jumps and wont stop jumping
The Script:
image

6 Likes

Add a number that if it’s over 2 jumps, it will not let you jump again and it resets if you land.

Also why is the jump keybind “W”? That’s like telling a criminal to give you money.

Edit: Also make the jump number increase by 1 everytime you jump and haven’t landed.

6 Likes

How can I set the jump to false after 2 jumps or in general set it to false, because i tried setting it to false and it didn’t work

maybe
script.disable = true

then it will go this again?

script.disable = false

i guess

Well if i didn’t make sense, i meant this:

Create a number variable with only 0, if you jump it will be increased by 1, if you jump again using velocity, it will increase by 1 again meaning it’s now 2, since it’s 2, create a if statement where you can’t boost up in the air via velocity anymore unless you land which would restart the number.

Edit: To replicate the same height of the jump power, the default jump power is 50, so set the velocity to 30 in y axis.

actually the script can be

if h:GetState(Enum.HumanoidStateType.Landed) then
print(“Landed”)
script.disable = true
wait(0.5)
script.disable = false

then it will make it so after you landed, the script will stop and you wont jump, and wait 0.5 (cooldown) then you can double jump again?

I’m trying to change some values wait a sec

It’s too kinda picky, the thing is you only wrote the disabled part after the player landed so they can still infinite jump but if they hit a part that leads to the humanoid state switching to landed state, they would be not be able to temporarily double jump for 0.5 seconds, then they would be able to infinite jump again.

1 Like

oh i was wrong oof, but i really want to try it :slight_smile: :slight_smile: :slight_smile:

If you’re having too much trouble trying to replicate what i explained, i might as well create a place that you could download later and copy the script.

Everything that I tried didn’t work

Did you know that “W” is known to move your character forwards so thats why when you are moving your character it will always jump. You should use Enum.KeyCode.Space, you can research all the possible keycodes you can use here.

Here’s a code i tried, it worked so your problem is probably gone now.

local player = game:GetService("Players").LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()

local humanoidRootPart = char:WaitForChild("HumanoidRootPart")
local humanoid = char:WaitForChild("Humanoid")

local jumpUsage = 1

local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(key, gp)
	if key.KeyCode == Enum.KeyCode.Space and not gp then
		if humanoidRootPart and humanoid then
			if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
				if jumpUsage >= 1 then
					jumpUsage -= 1
					humanoid:ChangeState(Enum.HumanoidStateType.Jumping, true)
					humanoid.StateChanged:Connect(function(old, new)
						if new == Enum.HumanoidStateType.Landed then
							jumpUsage = 1
						end
					end)
				end
			end
		end
	end
end)

Make sure it’s in starterpack, startergui or anywhere suitable and don’t forget it must be a local script!

8 Likes
-- i wont be adding variables like character, player, or humanoid, those can be taken
-- care easily

-----
--shorten the state types
local jumping = Enum.HumanoidStateType.Jumping;
local falling = Enum.HumanoidStateType.Freefall;
local landed = Enum.HumanoidStateType.Landed;

local doubleJump = false;


humanoid.StateChanged:Connect(function(old, new)
     if (old == falling) and (new == landed) then
          doubleJump = false;
          return;
     end

     if (old == jumping) and (new == falling) then
          doubleJump = true;
          coroutine.wrap(function() --optional
               wait(.8);
               doubleJump = false;
          end)()
     end
end)

uis.InputBegan:Connect(function(inp, gpe)
     if gpe then
          return;
     end

    if inp.KeyCode == Enum.KeyCode.Space then
          if (doubleJump) then
               doubleJump = false;
               humanoid:ChangeState(jumping);
          end
     end
end)

Try this one.

2 Likes

Can you define what does “gp” mean?

It either means game procession or process, we need that so the script doesn’t fire while your typing.

gpe stands for “game-processed event”. In order to simplify it, when someone is typing through a textbox GUI or is typing in chat, then that’s gpe. If we don’t want the entire contents of the inputbegan event to function if the player is typing through a textbox or is typing in a chat, we use an if statement to see if it’s a game-processed event.

It shows an error on “gp” is it supposed to be a variable?

gpe, not gp. You did it wrong. (ignore this, thought you were talking about my script)

If his doesn’t work, try mine. gp is supposed to be a parameter returned by inputbegan