Hasli4

Untitled

Sep 6th, 2026
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. local npc = script.Parent
  2. local humanoid = npc:WaitForChild("Humanoid")
  3. local root = npc:WaitForChild("HumanoidRootPart")
  4.  
  5. -- Точки патруля
  6. local pathFolder = workspace:WaitForChild("NPCPath")
  7. local corner = pathFolder:WaitForChild("Corner")
  8. local finish = workspace:WaitForChild("finish")
  9.  
  10. -- Настройки
  11. humanoid.WalkSpeed = 10
  12. humanoid.AutoRotate = true
  13.  
  14. -- Чтобы NPC полностью управлялся сервером
  15. root:SetNetworkOwner(nil)
  16.  
  17. -- Расстояние, на котором точка считается достигнутой
  18. local REACH_DISTANCE = 3
  19.  
  20. -- Движение к точке
  21. local function moveToPoint(target)
  22. while true do
  23. local distance = (root.Position - target.Position).Magnitude
  24.  
  25. -- Дошёл
  26. if distance <= REACH_DISTANCE then
  27. return
  28. end
  29.  
  30. -- Отправляем NPC к точке
  31. humanoid:MoveTo(target.Position)
  32.  
  33. task.wait(0.2)
  34. end
  35. end
  36.  
  37. -- Бесконечный патруль
  38. while true do
  39.  
  40. -- Corner -> finish
  41. moveToPoint(finish)
  42.  
  43. -- Небольшая пауза
  44. task.wait(0.5)
  45.  
  46. -- Разворот будет сделан автоматически Humanoid
  47. -- finish -> Corner
  48. moveToPoint(corner)
  49.  
  50. -- Небольшая пауза
  51. task.wait(0.5)
  52. end
Advertisement
Add Comment
Please, Sign In to add comment