Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local UserInputService = game:GetService("UserInputService")
- local Workspace = game:GetService("Workspace")
- local LocalPlayer = Players.LocalPlayer
- local teleportEnabled = false
- local function teleportPlayerBehind(enemy)
- local enemyRootPart = enemy:FindFirstChild("HumanoidRootPart")
- local playerCharacter = LocalPlayer.Character
- if enemyRootPart and playerCharacter then
- local playerRootPart = playerCharacter:FindFirstChild("HumanoidRootPart")
- if playerRootPart then
- local newPosition = enemyRootPart.Position - (enemyRootPart.CFrame.LookVector * 5)
- playerRootPart.CFrame = CFrame.new(newPosition)
- end
- end
- end
- local function getClosestEnemy()
- local closestEnemy = nil
- local closestDistance = math.huge
- for _, descendant in pairs(Workspace.Mobs:GetDescendants()) do
- if descendant:IsA("Model") and descendant:FindFirstChild("HumanoidRootPart") then
- local enemyPart = descendant:FindFirstChild("HumanoidRootPart")
- local distance = (LocalPlayer.Character.HumanoidRootPart.Position - enemyPart.Position).magnitude
- if distance < closestDistance then
- closestEnemy = descendant
- closestDistance = distance
- end
- end
- end
- return closestEnemy
- end
- local function onKeyPress(input, gameProcessed)
- if not gameProcessed then
- if input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.T then
- teleportEnabled = not teleportEnabled
- print("Teleport Enabled: ", teleportEnabled) -- Debug print
- end
- end
- end
- UserInputService.InputBegan:Connect(onKeyPress)
- local function continuousTeleport()
- while task.wait() do
- if teleportEnabled then
- local closestEnemy = getClosestEnemy()
- if closestEnemy then
- teleportPlayerBehind(closestEnemy)
- end
- end
- end
- end
- coroutine.wrap(continuousTeleport)()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement