Again, I've searched online for this and tried various ways, for example changing the Dist = 10000 to minDist = (whatever number) and also BestDist = (whatever number). I don't know if that was the right thing to do, sorry, Iam a total noob at lua language. Basically, I want the NPC to follow the player when the player reaches a certain distance from it. Please also tell me if there is a need for a different script or something, Thanks a lot. This is my chase script, what it does is, wherever I place the NPCs, they search the whole map for a player and follow him, e.g. from the other end of the map to the other, which is not what I want. -
local larm = script.Parent:FindFirstChild("HumanoidRootPart")
local rarm = script.Parent:FindFirstChild("HumanoidRootPart")
function findNearestTorso(pos)
local list = game.Workspace:children()
local torso = nil
local dist = 10000
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("HumanoidRootPart")
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(math.random(1,5))
local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
if target ~= nil then
script.Parent.Humanoid:MoveTo(target.Position, target)
end
end

9 comments
Stolen script! Please make your script!! XDDDDDDDDDDDDDDDDDDDD
Well hey atleast he atleast tried something unlike you who wanted someone to edit the script and give it to you. Also i have a suspicion that your account is a compromised account (unless of course you're trolling and acting like an immature child)
Also @YouEnglish do you mean you want the NPC stand still and then chase the player when a player is near it?
Thanks @GamingOverlord756 . It is a script I tried very hard to find - as you can see from my previous question a few months ago. I really need this to move on in making the game though.
And Yes @GamingOverlord756 - Just like the NPCs in the game Ro-Ghoul (for example)
Is the script located inside the player
No its inside the NPC - Check out my game - its in the chat
okay i did some googling. Try removing dist and change the line from magnitude < dist to magnitude == (how many studs you want)
can you put in the source please i am not understanding - i mean the pure line of code - won't reply for a while soz keep checking later on thx