Hello! I am in making of a 2007 roblox client inside of roblox but there is a big road block that I am stuck on. I’m trying to make the player not be able to change their velocity while in air/jumping, so basically no matter what the player does, the player keeps going in the same direction with the same speed until they hit the ground. I would really appreciate the help since I have been stuck on this for hours! (if you need a video demonstrating on what I mean please tell me!)
To make the player unable to change their velocity while in the air or jumping, you can modify the player’s Humanoid properties and handle the JumpingStateChanged event. Here’s an example of how you can achieve this:
local player = game.Players.LocalPlayer
local humanoid = player.Character and player.Character:FindFirstChildOfClass("Humanoid")
if humanoid then
local inAir = false -- Flag to track if the player is in the air
humanoid.JumpingStateChanged:Connect(function(_, state)
inAir = state == Enum.HumanoidStateType.Jumping
if inAir then
-- Disable player input while in the air
humanoid.WalkSpeed = 0
humanoid.AutoRotate = false
else
-- Restore player input when landing
humanoid.WalkSpeed = 16 -- Adjust the walk speed to your desired value
humanoid.AutoRotate = true
end
end)
end
In this example, we check if the player’s character exists and has a Humanoid instance. Then, we create a flag inAir
to track if the player is in the air or jumping. The JumpingStateChanged
event is connected to a function that is triggered when the player’s jumping state changes.
When the player is in the air, the function disables player input by setting the WalkSpeed to 0 and AutoRotate to false. This prevents the player from changing their velocity or rotation while in the air. Once the player lands, the function restores the original values for WalkSpeed and AutoRotate, allowing the player to move and rotate normally.
Make sure to adjust the walk speed value (16
in the example) to match your desired speed. Feel free to modify the code to fit your specific requirements and game setup.