I'm trying to make a zombie that comes after you once you're 50 studs away from it. However I do not know how to check how far away my character is from the zombie. I know there is a method for it, but I do not know that method. Here's what i have so far.
This is a server script inside the zombie.
local zombie = script.Parent
function getNearestTorso()
local nearestTorso = nil
for i,v in pairs(game.Player:GetPlayer()) do
if [distance from plr to zombie] <= 50 then
if nearestTorso ~= nil then
if [distance from nearestTorso to zombie] > [distance from plr to zombie] then
nearestTorso = v.Character.Torso
end
else
nearestTorso = v.Character.Torso
end
end
end
return nearestTorso
end
while true do
wait(3)
if getNearestTorso() ~= nil then
local tor = getNearestTorso()
zombie.Humanoid:MoveTo(tor.Position,tor)
end
end

3 comments
My code is fine... I just need to know how to get the distance one brick is from another.
Never mind... I saw 'maginitude' and did not know what it was, so I looked it up and it turns out it's just what I needed. Thanks.
Is there any way I can accept your answer? Or does this site work differently?