Attempt to compare number < vector3

heres the line of code that is affected:

if hit == obj or hit:FindFirstAncestor(obj.Parent.Name) and obj.Parent.HumanoidRootPart.AssemblyLinearVelocity > 1 then

at this line, i get the following error:
image

i know its because of the number, but i also dont know any other way to replace the number, as i want it to watch for a velocity above 1 in ANY direction when a raycast hits the player. any help?

AssemblyLinearVelocity is a Vector3 and you’re trying to compare it to a number.

Ideally, if you check for a Velocity in any direction you need to use Magnitude.

Magnitude is used to get the length of a Vector3.

The length of a Vector3 can be quickly summarized as a total of all three directions (x, y, z).

The correct usage would be this:

if AssemblyLinearVelocity.Magnitude > 1 then

image

ive used this before from a comment in a tutorial, and it actually didnt really help. it would stabily not kill the player at like 150 if they had no tool out, but would kill the player if they had, for example, a flashlight out

ill try it anyway

You need to specify which component of the vector3 you want to compare to 1.

if hit == obj or (hit:FindFirstAncestor(obj.Parent.Name) and obj.Parent.HumanoidRootPart.AssemblyLinearVelocity.x > 1) then
-- code to execute if the condition is true
end

I have added parentheses to group the “and” expression together and specified that I want to compare the x-component of the vector3 value “AssemblyLinearVelocity” to the number 1.

the error is fixed, but players die when a gear (like a flashlight) is held.

i fixed it by making the 1 a 50

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.