TheUnknownDiscord

chaos

Oct 19th, 2021 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function _G.follow(times)
  2. for i = 1, times do
  3. task.wait()
  4. local part1 = Instance.new("Part", game.Workspace)
  5. part1.Size = Vector3.new(1.487, 0.985, 2.72)
  6. local bg = Instance.new("BodyGyro",part1)
  7. bg.D = 100
  8. bg.P = 1000000000
  9. bg.MaxTorque = Vector3.new(1000000,1000000,1000000)
  10. local velocitylol = Instance.new("BodyVelocity", part1)
  11. coroutine.wrap(function()
  12. while true do
  13. task.wait()
  14. velocitylol.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  15. velocitylol.Velocity = part1.CFrame.LookVector * -32
  16. end
  17. end)()
  18. function move(target)
  19. local dir = (part1.Position - target.Position).unit
  20. local spawnPos = part1.Position
  21. local pos = spawnPos + (dir * 1)
  22. bg.cframe = CFrame.new(pos, pos + dir)
  23. end
  24.  
  25. function findNearestTorso(pos)
  26. local list = game.Workspace:GetChildren()
  27. local torso = nil
  28. local dist = 1000
  29. local temp = nil
  30. local human = nil
  31. local temp2 = nil
  32. for x = 1, #list do
  33. temp2 = list[x]
  34. if (temp2.className == "Model") and (temp2 ~= script.Parent) then
  35. temp = temp2:findFirstChild("Head")
  36. human = temp2:findFirstChild("Humanoid")
  37. if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
  38. if (temp.Position - pos).magnitude < dist then
  39. torso = temp
  40. dist = (temp.Position - pos).magnitude
  41. end
  42. end
  43. end
  44. end
  45. return torso
  46. end
  47. coroutine.wrap(function()
  48. while true do
  49. local torso = findNearestTorso(part1.Position)
  50. if torso~=nil then
  51. move(torso)
  52. end
  53. task.wait()
  54. end
  55. end)()
  56. end
  57. end
Add Comment
Please, Sign In to add comment