Simple, I have a killer npc and I want him to kill any player within 5 stud radius, how do I do it without making a big hitbox part?
✓ ANSWER ACCEPTED
How to detect player if player is 5 studs away?
1 answer
✓ Accepted answer
There's a thing called magnitude. An example would be:
local distance = Vector3.new(0,10,0)
local distance2 = Vector3.new(0,-10,0)
local magnitude = (distance - distance2).magnitude
print(magnitude)
This would print "20" in the output.
For a more in-depth explanation view the Roblox Wiki.
Anyway, magnitude is used to find the distance between one point to the other.
In your case, you want to find the distance between a player and an enemy.
I won't write an entire script for AI but just use your current code and find a way to put this in:
local magnitude = (enemyName.Position - characterDetected.Position).magnitude
print(magnitude) -- you can delete this if you want
if magnitude <= 5 then
characterDetected.Humanoid.Health = 0
end
I hope this helps!
This discussion is preserved as it was. New answers, comments, and votes are closed.

6 comments
Additional info, magnitude is not only used to get the distance between two vectors, but rather gets the length of a vector.
Subtracting 2 vectors creates a new vector from vector 1 (part1's position) to vector 2 (part2's position).
Using magnitude gets the length of the new vector, thus getting the distance.
Reference: https://create.roblox.com/docs/reference/engine/datatypes/Vector3#Magnitude
Thank you, T3! I actually didn't know that... it's always nice to know more! Thank you!
The problem is that my entity has no pathfinding ai it just runs trought the whole map so i dont have anything that can detect player