Limiting Player Y Velocity

Hallo!

What do I want to achieve? I would like limit how fast the player can fall. For example, gaining speed while falling until traveling at 50 meters/second then staying at that speed until the player stops falling. Not just continuously speeding up.

What is the issue? I know how to script a bit but not tone so this is really outside of my comfort zone/what I know how to do. I have looked online for a while and could not find anything about this topic (I’m kind of lost). If anyone could help me figure out how to achieve or suggest anything that would be great.

Hi, there are unfortunately no ways to limit the characters Y axis velocity directly, but you can update its velocity every frame (using RunService) to get below the velocity limit if it is outside of its bounds. However i do not recommend this, because its really bad performance-wise. But you can also make it only update when the players HumanoidState is in the Freefall state which does make it a bit better.

Place this inside of a server script in ServerScriptService.

local players = game:GetService("Players")
local runService = game:GetService("RunService")

local fallSpeedLimit = -100

local function onCharacterAdded(char)
	local hum = char:WaitForChild("Humanoid")
	local root = char:WaitForChild("HumanoidRootPart")
	local connection

	local function onStateChanged(_, newState)
		print(newState)
		if newState == Enum.HumanoidStateType.Freefall then
			connection = runService.Heartbeat:Connect(function()
				local velocity = root.Velocity
				print(velocity)
				if velocity.Y < fallSpeedLimit then
					root.Velocity = Vector3.new(velocity.X, fallSpeedLimit, velocity.Z)
				end
			end)
		elseif connection then
			connection:Disconnect()
			connection = nil
		end
	end

	hum.StateChanged:Connect(onStateChanged)
end

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(onCharacterAdded)
end)

This script has a 3% activity when a single player is falling, imagine how much the game would lag with multiple players falling, I DO NOT RECOMMEND THIS.

There could be a much better way to do this that im missing, so just lmk if this is stupid lol.

2 Likes

I will just try it out and see how well it works. I might try to build on this, thank you!

I have another solution that worked for me, it is just using RenderStepped to update the velocity each frame. Put it in starter player scripts as a local script.

local plrs = game:GetService("Players")
local RunService = game:GetService("RunService")

local plr = plrs.LocalPlayer
local char = player.Character
local hrp = char:WaitForChild("HumanoidRootPart")

local max = -50

RunService.RenderStepped:Connect(function()
	if hrp then
		local velocity = hrp.Velocity
		if velocity.Y < max then
			hrp.Velocity = Vector3.new(velocity.X, max, velocity.Z)
		end
	end
end)
1 Like

Great, thanks so much ! I will also try this one out and see how it goes.

You could set the gravity property of workspace to 50

But he wants the player to cap at a certain amount. Gravity applies a force, which can lead to really fast speeds.

Like supergreendude14 said I want to limit the falling speed not how fast it takes to get to that speed.

You could use runservice for that, like the comments above said, but it would be very costly for the game to run that when you have many players, especially if its not the main feature of the game, or you could apply a vectorforce in the opposite direction.

Thanks for the information I will keep messing around with this.

:cool: Basically use a LinearVelocity instnace.