Advertisement
KINGOFCOOL

Untitled

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