Advertisement
xpa1nx0

testazxc

Dec 1st, 2023 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. local teleportEnabled = false
  2. local UserInputService = game:GetService("UserInputService")
  3.  
  4. -- Function to find the closest NPC
  5. local function findClosestNPC()
  6. local character = game.Players.LocalPlayer.Character
  7. local humanoidRootParts = {}
  8.  
  9. local npcFolder = game.Workspace.Live.NPCs.Client
  10.  
  11. -- Collect all NPC humanoid root parts in the specified folder
  12. for _, npc in ipairs(npcFolder:GetChildren()) do
  13. if npc:IsA("Model") and npc:FindFirstChild("HumanoidRootPart") and npc:FindFirstChild("Humanoid") and npc.Humanoid.Health > 0 then
  14. table.insert(humanoidRootParts, npc.HumanoidRootPart)
  15. end
  16. end
  17.  
  18. local closestRootPart = nil
  19. local closestDistance = math.huge
  20. local myPosition = character:WaitForChild("HumanoidRootPart").Position
  21.  
  22. -- Find the closest NPC humanoid root part
  23. for _, rootPart in ipairs(humanoidRootParts) do
  24. local distance = (rootPart.Position - myPosition).Magnitude
  25. if distance < closestDistance then
  26. closestRootPart = rootPart
  27. closestDistance = distance
  28. end
  29. end
  30.  
  31. return closestRootPart
  32. end
  33.  
  34. -- Teleport function
  35. local function teleportToClosestNPC()
  36. local character = game.Players.LocalPlayer.Character
  37. local closestRootPart = findClosestNPC()
  38.  
  39. -- Teleport the character to the closest NPC humanoid root part
  40. if closestRootPart then
  41. local behindPosition = closestRootPart.Position - (closestRootPart.CFrame.LookVector * 4)
  42. character:MoveTo(behindPosition)
  43.  
  44. -- Simulate a mouse click
  45. mouse1click()
  46. else
  47. print("No NPCs found.")
  48. end
  49. end
  50.  
  51. -- Simulate a mouse click function
  52. local function mouse1click()
  53. local input = Instance.new("InputObject", game)
  54. input.UserInputType = Enum.UserInputType.MouseButton1
  55. UserInputService.InputBegan:Fire(input)
  56. wait()
  57. UserInputService.InputEnded:Fire(input)
  58. input:Destroy()
  59. end
  60.  
  61. -- Function to toggle teleportation on/off
  62. local function toggleTeleport()
  63. teleportEnabled = not teleportEnabled
  64. if teleportEnabled then
  65. print("Auto-Teleportation enabled. Press 'T' to toggle off.")
  66. while teleportEnabled do
  67. teleportToClosestNPC()
  68. wait()
  69. end
  70. else
  71. print("Auto-Teleportation disabled.")
  72. end
  73. end
  74.  
  75. -- Toggle teleportation when 'T' key is pressed
  76. UserInputService.InputBegan:Connect(function(input)
  77. if input.KeyCode == Enum.KeyCode.T then
  78. toggleTeleport()
  79. end
  80. end)
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement