Say I make a raycast and get the data from it like so:
local ray = Ray.new(origin, direction)
local hitPart, hitPosition = workspace:FindPartOnRay(ray, origin)
If the origin was 10 or less studs away, it would move, but if not it would stay.
How would I let the script know if the origin was 10 or less studs away from the “hitPart”?
this old method is deprecated, use the new workspace:Raycast() instead of findpartonray, also you put local local instead of local, and what is the “origin”, you can use ToObjectSpace to get the distance or use the unit * distance
So to measure the distance between the origin and the hit position in the example scenario you can do this:
--Vector travels from origin of where ray is cast to the hit position
local travelVector = hitPosition - origin
--Get's the distance
print(travelVector.Magnitude)
Yep thats one way to do it. Keep in mind that the Vector3.Magnitude can be fairly resource intensive as it performs sqrt(x^2 + y^2 + z^2) math as explained in this topic: