local Players = game:GetService("Players")
local zombie = script.Parent
local humanoid = zombie:WaitForChild("Humanoid")
-- Радиус обнаружения (в studs). Поставь нужное значение.
local DETECTION_RANGE = 100
-- Функция: получить HumanoidRootPart ближайшего живого игрока
local function getNearestPlayerTarget(position)
local nearestPart = nil
local nearestDist = DETECTION_RANGE
for _, player in ipairs(Players:GetPlayers()) do
local character = player.Character
if not character then
continue
end
local targetHumanoid = character:FindFirstChildOfClass("Humanoid")
local targetRoot = character:FindFirstChild("HumanoidRootPart")
or character:FindFirstChild("Torso") -- фоллбэк для R6
if targetHumanoid and targetRoot and targetHumanoid.Health > 0 then
local dist = (targetRoot.Position - position).Magnitude
if dist < nearestDist then
nearestPart = targetRoot
nearestDist = dist
end
end
end
return nearestPart
end
-- Основной цикл
while humanoid.Health > 0 do
task.wait(0.5)
local myRoot = zombie:FindFirstChild("HumanoidRootPart")
or zombie:FindFirstChild("Torso")
if myRoot then
local target = getNearestPlayerTarget(myRoot.Position)
if target then
humanoid:MoveTo(target.Position)
end
end
end