Advertisement
Navarone19_CH

Kill Follow Script

Jan 9th, 2021
15,306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. --Follow Script
  2. function findNearestPlayer(Position)
  3. wait(0.3)
  4. local List = game.Workspace:children()
  5. local Torso = nil
  6. local Distance = 30
  7. local Temp = nil
  8. local Human = nil
  9. local Temp2 = nil
  10. for x = 1, #List do
  11. Temp2 = List[x]
  12. if (Temp2.className == "Model") and (Temp2 ~= script.Parent) then
  13. Temp = Temp2:findFirstChild("HumanoidRootPart")
  14. Human = Temp2:findFirstChild("Humanoid")
  15. if (Temp ~= nil) and (Human ~= nil) and (Human.Health > 0) then
  16. if (Temp.Position - Position).magnitude < Distance then
  17. Torso = Temp
  18. Distance = (Temp.Position - Position).magnitude
  19. end
  20. end
  21. end
  22. end
  23. return Torso
  24. end
  25.  
  26.  
  27.  
  28.  
  29. while true do
  30. local target = findNearestPlayer(script.Parent.HumanoidRootPart.Position)
  31. if target ~= nil then
  32. script.Parent.Humanoid:MoveTo(target.Position, target)
  33. end
  34. end
  35.  
  36.  
  37.  
  38. --Kill Script
  39. local function onTouch(Touch)
  40. if Touch.Parent:FindFirstChild("Humanoid") ~= nil then
  41. Touch.Parent.Humanoid.Health = 0
  42.  
  43. end
  44. end
  45.  
  46. script.Parent.HumanoidRootPart.Touched:Connect(onTouch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement