Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local teleportEnabled = false
- local UserInputService = game:GetService("UserInputService")
- -- Function to find the closest NPC
- local function findClosestNPC()
- local character = game.Players.LocalPlayer.Character
- local humanoidRootParts = {}
- local npcFolder = game.Workspace.Live.NPCs.Client
- -- Collect all NPC humanoid root parts in the specified folder
- for _, npc in ipairs(npcFolder:GetChildren()) do
- if npc:IsA("Model") and npc:FindFirstChild("HumanoidRootPart") and npc:FindFirstChild("Humanoid") and npc.Humanoid.Health > 0 then
- table.insert(humanoidRootParts, npc.HumanoidRootPart)
- end
- end
- local closestRootPart = nil
- local closestDistance = math.huge
- local myPosition = character:WaitForChild("HumanoidRootPart").Position
- -- Find the closest NPC humanoid root part
- for _, rootPart in ipairs(humanoidRootParts) do
- local distance = (rootPart.Position - myPosition).Magnitude
- if distance < closestDistance then
- closestRootPart = rootPart
- closestDistance = distance
- end
- end
- return closestRootPart
- end
- -- Teleport function
- local function teleportToClosestNPC()
- local character = game.Players.LocalPlayer.Character
- local closestRootPart = findClosestNPC()
- -- Teleport the character to the closest NPC humanoid root part
- if closestRootPart then
- local behindPosition = closestRootPart.Position - (closestRootPart.CFrame.LookVector * 4)
- character:MoveTo(behindPosition)
- -- Simulate a mouse click
- mouse1click()
- else
- print("No NPCs found.")
- end
- end
- -- Simulate a mouse click function
- local function mouse1click()
- local input = Instance.new("InputObject", game)
- input.UserInputType = Enum.UserInputType.MouseButton1
- UserInputService.InputBegan:Fire(input)
- wait()
- UserInputService.InputEnded:Fire(input)
- input:Destroy()
- end
- -- Function to toggle teleportation on/off
- local function toggleTeleport()
- teleportEnabled = not teleportEnabled
- if teleportEnabled then
- print("Auto-Teleportation enabled. Press 'T' to toggle off.")
- while teleportEnabled do
- teleportToClosestNPC()
- wait()
- end
- else
- print("Auto-Teleportation disabled.")
- end
- end
- -- Toggle teleportation when 'T' key is pressed
- UserInputService.InputBegan:Connect(function(input)
- if input.KeyCode == Enum.KeyCode.T then
- toggleTeleport()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement