Hi, I was wondering if you guys knew of a way I could make my monster follow a character but not close the gap between the two at a certain distance (not sure what the distance is going to be yet but not far). The goal I am trying to reach is to make it go towards the character then stop at the distance, but it won't run away from the player when they are the ones walking at it. Is there a way to do this?
This is the current following script that I am working with right now. If you need any other information don't hesitate to ask. :) Thank you, Peanutthedestoyer
local larm = script.Parent:FindFirstChild("Left Arm")
local rarm = script.Parent:FindFirstChild("Right Arm")
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 20 --this is the distance your monster will see you
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("Torso")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
while true do
wait(0.1)
local target = findNearest(PlayerTorso(script.Parent.Torso.Position)
if target ~= nil then--
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end

3 comments
I tried it and it didn't want to work so I read through it all. It seems like you made it go to the torsos' position if it was further than the given distance away and to move to the torso if it was closer than that too. Though thanks for the help :)
There were two different variables the function and I was in a bit of a rush( Sorry :) ) So I didn't pay that much attention to the other distance variable "distance". I will edit my answer as soon as I fix this.
Alright the new script it up.