How should I make double jumping with my custom character controller

Hello everyone,

I am trying to make a custom 2.5d character controller, but I have no idea how to implement double jumping.

This is my script at the moment:

game.ReplicatedStorage.movementEvent.jumpEvent.OnServerEvent:Connect(function(plr)
	
	local function jump()
		
		local velocity = plr.Character.HumanoidRootPart.LinearVelocity --This is the body mover I use for moving the character
		local jumpPower = 50
		
		velocity.VectorVelocity = Vector3.new(velocity.VectorVelocity.X, jumpPower, 0)
		
		for i = 1, 25 do
			velocity.VectorVelocity = Vector3.new(velocity.VectorVelocity.X, jumpPower - i * 4, 0)
			wait()
		end
		
	end
	
	if plr.Character.Humanoid.FloorMaterial then
		jump()
		plr.Character.Properties.doubleJump.Value = true
	elseif plr.Character.Properties.doubleJump.Value == true then
		jump()
		plr.Character.Properties.doubleJump.Value = false
	end
	
end)

The problem is that if the player double jumps while the jump() function is still running, the player’s character will kinda float in the air and then land on the floor.

How can I fix it?

I wouldn’t make a jump event on the server, it makes the game a lot more stuttery and ping based. (and hackers can just change their client position anytime lol). its also a bad idea because that would have the player’s vectorvelocity being sent every two frames, (which is a big hit to your networking)

and also to solve your jump overlapping you can do threading
(in a localscript)

local CurJumpThread
local CurJumps = 0
local MaxJumps = 2

function Jump()
  if Humanoid.FloorMaterial then
    CurJumps = DoubleJumps
  end
  if CurJumps <= 0 then
    return
  end
  
  if CurJumpThread then task.cancel(CurJumpThread) end
  Jumps -= 1

  CurJumpThread = task.spawn(function()
    --jump code, including for loops and everything
  end)
end

--bind Jumping input to Jump down here

the code above is just example, do note it will be very hard to implement Coyote Frames with this method but the other ways are more complicated lol

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.