Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there a way to get the distance between two objects?

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.

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).

1 comment

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.