Is there a way to get the distance between two objects? I looked for this on the wiki but I didn't find anything. If it is possible, I want to make is so that if an object gets within a certain distance, something would happen.
✓ ANSWER ACCEPTED
Is there a way to get the distance between two objects?
1 answer
✓ Accepted answer
If checking the distance between a player and an object:
function getDistance(player, object)
return player:GetDistanceFromCharacter(object.Position)
end
Otherwise, use the following.
function getDistance(object1, object2)
return (object1.Position - object2.Position).magnitude
end
Both functions return the distance in studs between the two objects (or player and object).
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thanks