Advertisement
fomm1802

ติดตามสคริปต์

Dec 23rd, 2021
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. function findNearestTorso(pos)
  2. local list = game.Workspace:children()
  3. local torso = nil
  4. local dist = 1000
  5. local temp = nil
  6. local human = nil
  7. local temp2 = nil
  8. for x = 1, #list do
  9. temp2 = list[x]
  10. if (temp2.className == "Model") and (temp2 ~= script.Parent) then
  11. temp = temp2:findFirstChild("Torso")
  12. human = temp2:findFirstChild("Humanoid")
  13. if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
  14. if (temp.Position - pos).magnitude < dist then
  15. torso = temp
  16. dist = (temp.Position - pos).magnitude
  17. end
  18. end
  19. end
  20. end
  21. return torso
  22. end
  23. --wait(math.random(0,5)/10)
  24. while true do
  25. wait(0.5)
  26. local target = findNearestTorso(script.Parent.Torso.Position)
  27. if target ~= nil then
  28. script.Parent.Humanoid:MoveTo(target.Position, target)
  29. end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement