Hasli4

Untitled

Apr 26th, 2026
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2.  
  3. function findNearestTorso(pos)
  4. local list = workspace:GetChildren()
  5. local torso = nil
  6. local dist = math.huge
  7.  
  8. for _, model in ipairs(list) do
  9. if model:IsA("Model") and model ~= script.Parent then
  10. -- берём только персонажей игроков
  11. local player = Players:GetPlayerFromCharacter(model)
  12. if player then
  13. local temp = model:FindFirstChild("HumanoidRootPart")
  14. local human = model:FindFirstChild("Humanoid")
  15.  
  16. if temp and human and human.Health > 0 then
  17. local newDist = (temp.Position - pos).Magnitude
  18. if newDist < dist then
  19. torso = temp
  20. dist = newDist
  21. end
  22. end
  23. end
  24. end
  25. end
  26.  
  27. return torso
  28. end
  29.  
  30. while true do
  31. task.wait(1)
  32. local target = findNearestTorso(script.Parent.HumanoidRootPart.Position)
  33. if target ~= nil then
  34. script.Parent.N1:MoveTo(target.Position, target)
  35. end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment