Advertisement
aesnike

Good tp???

Oct 28th, 2024
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. -- Function to find the nearest NPC
  2. local function findNearestNPC()
  3. local nearestNPC = nil
  4. local nearestDistance = math.huge
  5. local Character = game.Players.LocalPlayer.Character
  6.  
  7. if not Character or not Character.HumanoidRootPart then return end
  8.  
  9. for _, folder in ipairs(workspace:GetChildren()) do
  10. if folder:IsA("Folder") then
  11. for _, child in ipairs(folder:GetChildren()) do
  12. if child:FindFirstChild("enemyFolder") then
  13. for _, npc in ipairs(child.enemyFolder:GetChildren()) do
  14. if npc:FindFirstChild("HumanoidRootPart") and npc:FindFirstChild("Humanoid") and npc.Humanoid.Health > 0 then
  15. local distance = (Character.HumanoidRootPart.Position - npc.HumanoidRootPart.Position).Magnitude
  16. if distance < nearestDistance then
  17. nearestDistance = distance
  18. nearestNPC = npc
  19. end
  20. end
  21. end
  22. end
  23. end
  24. end
  25. end
  26. return nearestNPC
  27. end
  28.  
  29. -- Function to check nearby mobs
  30. local function isNearMobs(range)
  31. local Character = game.Players.LocalPlayer.Character
  32. if not Character or not Character.HumanoidRootPart then return false end
  33.  
  34. for _, folder in ipairs(workspace:GetChildren()) do
  35. if folder:IsA("Folder") then
  36. for _, child in ipairs(folder:GetChildren()) do
  37. if child:FindFirstChild("enemyFolder") then
  38. for _, npc in ipairs(child.enemyFolder:GetChildren()) do
  39. if npc:FindFirstChild("HumanoidRootPart") and npc:FindFirstChild("Humanoid") and npc.Humanoid.Health > 0 then
  40. local distance = (Character.HumanoidRootPart.Position - npc.HumanoidRootPart.Position).Magnitude
  41. if distance <= range then
  42. return true
  43. end
  44. end
  45. end
  46. end
  47. end
  48. end
  49. end
  50. return false
  51. end
  52.  
  53. -- Function to stay on top of target
  54. local function stayOnTopOfTarget()
  55. local Character = game.Players.LocalPlayer.Character
  56. local targetNPC = findNearestNPC()
  57. local offset = Vector3.new(0, 9, 0) -- Adjust this value as needed
  58.  
  59. if not targetNPC or not targetNPC.Parent or not targetNPC:FindFirstChild("HumanoidRootPart") then
  60. wait(2) -- 2 second delay before finding next target
  61. return
  62. end
  63.  
  64. if Character and Character:FindFirstChild("HumanoidRootPart") and targetNPC and targetNPC:FindFirstChild("HumanoidRootPart") then
  65. local npcPosition = targetNPC.HumanoidRootPart.Position
  66. local cframe = CFrame.new(npcPosition + offset, npcPosition)
  67. Character.HumanoidRootPart.CFrame = cframe
  68. end
  69. end
  70.  
  71. -- Main loop example (you can modify this part)
  72. game:GetService("RunService").Heartbeat:Connect(function()
  73. stayOnTopOfTarget()
  74. wait(2) -- 2 second delay between teleports
  75. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement