So lets say the Player Character is falling and has a Y velocity of 95, How can I change that to something like 50 on a LocalScript?
You could use math.min
to cap the velocity for the Y axis - math.min
is a part of the math library that returns the minimum number. For example
local VelocityX, VelocityY, VelocityZ = Velocity.X, Velocity.Y, Velocity.Z;
VelocityY = math.min(VelocityY, 50); -- Returns "VelocityY" if it's <= 50, otherwise return 50
I hope this helped.
EDIT
You can overwrite the Velocity of the player’s HumanoidRootPart
to a new Vector3 with the variables.
RootPart.Velocity = Vector3.new(VelocityX, VelocityY, VelocityZ);
I already know that but I want to CHANGE the players Y velocity, not detect it.
it should be something like this:
Velocity = Vector3.new(0,5,0)--middle number is always Y.
Then changes the humanoidRootParts velocity
I decided to make another reply to expand upon a bit more. When the player falls, it’s velocity on the y axis will be a negative number - since that’s the case, we’ll actually need to use math.max
to be able to cap it. math.max
is also a part of the math library the returns the maximum number.
local VelocityY = math.max(RootPart.Velocity.Y, -50);
Since we now have a variable that has the velocity capped, we can overwrite the HumanoidRootPart’s velocity to a new vector3 with the variables.
-- Assuming VelocityX and VelocityZ were declared previously
RootPart.Velocity = Vector3.new(VelocityX, VelocityY, VelocityZ);
I hope this helped.