local Players = game:GetService("Players")
local Mob = script.Parent
local Enemy = Mob:FindFirstChildOfClass("Humanoid")
local mtemp = Mob.HumanoidRootPart
local _M = require(Mob:WaitForChild("MobConfig"))
local dist = _M.FollowDistance
local distnear = _M.FollowNear
FindNearestTorso = function()
for _,v in pairs(Players:GetPlayers()) do
local chr = v.Character
if chr and chr:FindFirstChild("HumanoidRootPart") and Mob:FindFirstChild("HumanoidRootPart") then
local temp = chr.HumanoidRootPart
local human = chr.Humanoid
if human.Health > 0 and (temp.Position - mtemp.Position).Magnitude < dist then
local HRoot = temp
local hum = human
Enemy:MoveTo(HRoot.Position - CFrame.new(mtemp.Position, HRoot.Position).LookVector * distnear)
end
end
end
end
while true do
FindNearestTorso()
wait(_M.FollowDelay)
end
I have multiple mobs so they are poor performance because many loop scripts work.