Player suddenly stops moving when jumping

I am trying to make a LocalScript which modifies the player’s ability to jump top be similar to Old Roblox, not being able to change direction when you jump. You probably already know the issue, but the issue is that when I am moving in a straight line and I jump, I suddenly stop moving.

local Humanoid = script.Parent:WaitForChild("Humanoid")

local Player = game:GetService("Players").LocalPlayer
local PlayerScripts = Player.PlayerScripts

local PlayerModule = require(PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()

Humanoid.StateChanged:Connect(function(old,new)
	if new == Enum.HumanoidStateType.Jumping then
		Humanoid.AutoRotate = false
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping,false)
		Controls:Disable()
	elseif new == Enum.HumanoidStateType.Landed then
		Humanoid.AutoRotate = true
		Controls:Enable()
		task.wait(1)
		Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping,true)
	end
end)

7 Likes

when you disable the controls, you stop it from detecting your move direction. since it says your movedirection is Vector3.new(0, 0, 0), it no longer moves you forward. you’d have to log their current X and Z velocity as soon as they jump and use either a BodyVelocity or LinearVelocity to continue handling their velocity.

Alternatively, you can fork over the ControlModule and if your Humanoid.FloorMaterial is Air then stop it from updating your move direction so it constantly keeps the last known movement direction.

2 Likes

How can I do that?

{{Filler-Filler-Filler}}

1 Like

which method are you attempting? artificial velocity or altering the ControlModule

1 Like

The issue you’re facing is likely due to the line Controls:Disable() which is disabling player input while jumping. This is causing the character to stop moving when you jump.

So to fix this, you don’t need to disable player input. you can fix this by modifying the character’s physics instead.

  1. you can use Humanoid:Move(Vector3.new(0, 0, 0) to disable character’s root motion

  2. then just you disable/enable char rotation.

local Humanoid = script.Parent:WaitForChild("Humanoid")

local Player = game:GetService("Players").LocalPlayer

Humanoid.StateChanged:Connect(function(old, new)
    if new == Enum.HumanoidStateType.Jumping then
        Humanoid:Move(Vector3.new(0, 0, 0), false)

    
        Humanoid.AutoRotate = false
    elseif new == Enum.HumanoidStateType.Physics then
        Humanoid.AutoRotate = true
    end
end)

hope this helps you! peace

3 Likes

Doesn’t work I think? I don’t know if I am doing it correctly just by replacing the my code with your code.

Edit: I’m stupid, agh, but it doesn’t seem to work sadly enough.

1 Like

Editing the ControlModule

{FILLER FILLER AAAA}

i’m checking out the module, it appears on line 546 theres a function called self.moveFunction. in this function it passed the localplayer, the moveVector it gets from the controls, and a false value. what you could do is fork this over and be like:

if Player.LocalPlayer.Character and Player.LocalPlayer.Character:FindFirstChild'Humanoid' and Player.LocalPlayer.Character.Humanoid.FloorMaterial ~= Enum.Materials.Air then
    self.moveFunction(Players.LocalPlayer, moveVector, false)
end

its a scrambled mess but its the general idea

FYI this is in the same module where you call the :Disable() and :Enable() methods

Can’t you just set their walkspeed to 0 when they jump and set it back to 16 when they land?

I don’t think that would even work tbh

1 Like

Whenever the player moves they are always using the walkspeed. If it is immediately set to 0 the player just freezes.

Might try that later, I highly doubt it will work, though.

1 Like

Tried your solution, it failed sadly.

rip, i guess that wasn’t the movement update function. i’d poke around in that script trying to find where it gets inputted, however if you don’t wanna spend that much time on it, it’d be easier to make a bodymover approach

1 Like

Save the humanoid Move Direction before you disable the controls and then re-apply it after.

local moveDirection = Humanoid.MoveDirection
Controls:Disable()
Humanoid.MoveDirection = moveDirection

EDIT: Replace Humanoid.MoveDirection with Humanoid:Move(), thank you @XXXTMS

4 Likes

The issue with this is that the player can still keep moving. OP wants to force players to be unable to move while in the air.

1 Like

You can’t edit the Humanoid’s MoveDirection property

1 Like

try using Controls:Disable()

Try using this method:

local Humanoid = script.Parent:WaitForChild("Humanoid")

local Player = game:GetService("Players").LocalPlayer
local PlayerScripts = Player.PlayerScripts

local PlayerModule = require(PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()

local isJumping = false


local function DisablePlayerInput()
    Controls:Disable()
end


local function EnablePlayerInput()
    Controls:Enable()
end

Humanoid.StateChanged:Connect(function(old, new)
    if new == Enum.HumanoidStateType.Jumping then
        Humanoid.AutoRotate = false
        isJumping = true
        DisablePlayerInput()
    elseif new == Enum.HumanoidStateType.Freefall then
        isJumping = false
        DisablePlayerInput()
    elseif new == Enum.HumanoidStateType.Seated or new == Enum.HumanoidStateType.Physics then
  
        isJumping = false
        DisablePlayerInput()
    elseif new == Enum.HumanoidStateType.Climbing or new == Enum.HumanoidStateType.Swimming then
        isJumping = false
        DisablePlayerInput()
    else
 
        if isJumping then

            Humanoid.AutoRotate = true
            task.wait(0.1)  
            EnablePlayerInput()
            isJumping = false
        end
    end
end)

The player needs to be able to keep moving while in the air, make sure to add Humanoid:Move() after Controls have been disabled to the character keeps moving.