Guest

Зомби скрит

Oct 11th, 2026
40
0
Never
Not a member of GistPad yet? Sign Up, it unlocks many cool features!
Lua 6.85 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2.  
  3. local zombie = script.Parent
  4. local humanoid = zombie:WaitForChild("Humanoid")
  5.  
  6. -- Радиус обнаружения (в studs). Поставь нужное значение.
  7. local DETECTION_RANGE = 100
  8.  
  9. -- Функция: получить HumanoidRootPart ближайшего живого игрока
  10. local function getNearestPlayerTarget(position)
  11. local nearestPart = nil
  12. local nearestDist = DETECTION_RANGE
  13.  
  14. for _, player in ipairs(Players:GetPlayers()) do
  15. local character = player.Character
  16. if not character then
  17. continue
  18. end
  19.  
  20. local targetHumanoid = character:FindFirstChildOfClass("Humanoid")
  21. local targetRoot = character:FindFirstChild("HumanoidRootPart")
  22. or character:FindFirstChild("Torso") -- фоллбэк для R6
  23.  
  24. if targetHumanoid and targetRoot and targetHumanoid.Health > 0 then
  25. local dist = (targetRoot.Position - position).Magnitude
  26. if dist < nearestDist then
  27. nearestPart = targetRoot
  28. nearestDist = dist
  29. end
  30. end
  31. end
  32.  
  33. return nearestPart
  34. end
  35.  
  36. -- Основной цикл
  37. while humanoid.Health > 0 do
  38. task.wait(0.5)
  39.  
  40. local myRoot = zombie:FindFirstChild("HumanoidRootPart")
  41. or zombie:FindFirstChild("Torso")
  42.  
  43. if myRoot then
  44. local target = getNearestPlayerTarget(myRoot.Position)
  45. if target then
  46. humanoid:MoveTo(target.Position)
  47. end
  48. end
  49. end
RAW Paste Data Copied