while wait() do
distance = (player.Character.Torso.CFrame.p - script.Parent.Torso.CFrame.p).magnitude
if distance > 10 then
--Following code
elseif distance <= 10 then
--Stop following code
end
end
You need to use magnitude to find the distance away from.
Along that you need to move the humanoid to a point.
Humanoid:MoveTo(Vector3.new(), Humanoid.Parent.Torso)
Use lerp.