scriptingtales

AhimsTestRoblox

Jun 3rd, 2023
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. function findTorso(pos)
  2. local torso = nil
  3. local dist = 75
  4. local child = workspace:children()
  5. for i=1, #child do
  6. if child[i].className == "Model" then
  7. local h = child[i]:findFirstChild("Humanoid")
  8. if h ~= nil then
  9. local check = child[i]:findFirstChild("Torso")
  10. if check ~= nil then
  11. if (check.Position - pos).magnitude < dist then
  12. torso = check
  13. dist = (check.Position - pos).magnitude
  14. end
  15. end
  16. end
  17. end
  18. end
  19. return torso
  20. end
  21.  
  22. while true do
  23. wait()
  24. local torso = findTorso(script.Parent.Position)
  25. if torso ~= nil then
  26. script.Parent.CFrame = CFrame.new(script.Parent.Position, torso.Position)
  27. end
  28. end
  29.  
Add Comment
Please, Sign In to add comment