This is more of a math issue than a script issue, but an issue never the less. I’m trying to make a script that tracks a players velocity as part of an anti-exploit. Below are the velocity outputs for the HumanoidRootPart
. The first output is for walking forward, the second for walking diagonally. I need the script to make it have the same velocity output(without exploits), regardless of direction.
2 Likes
That’s why you check the magnitude of the velocity so the direction the player is going doesn’t matter to your script.
Ok, so how can I implement this?
.Magnitude gets the “length” of something:
local pos1 = Vector3.new(0,5,0)
local pos2 = Vector3.new(0,10,5)
print((pos1 - pos2).Magnitude)
-- >> 7.0710678100586
Yes, but how can I make a script that measures the magnitude of a part?
What do you mean by the “magnitude of a part”?
You literally get the velocity of humanoidrootpart and then get it’s magnitude.
Here is an example.
local HumanoidRootPart = game.Players["Player1"].Character.HumanoidRootPart --This part is just for an example.
local RunService = game:GetService("RunService")
while true do
RunService.Heartbeat:Wait()
print(HumanoidRootPart.Velocity.Magnitude) --This usually prints 16-17 at max if the walkspeed is the default(16) and player is moving on a stable surface without jumping. It can go up to 55-60 if player is jumping on stable surface while walking.
end
1 Like
Ok, that works. Now, is there a way to negate the Y velocity? (from falling and jumping)
HumanoidRootPart.Velocity.X
(or Z).Magnitude
Actually, this just returns 1 number. You could try turning it into a Vector2?
1 Like
(HumanoidRootPart.Velocity * Vector3.new(1, 0, 1)).Magnitude
Thank you all for your help. I have gotten the script to work as intended.
1 Like