local UserInputService = game:GetService("UserInputService") local Players = game:GetService("Players") local player = Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoidRootPart = character:WaitForChild("HumanoidRootPart") local originalPosition = nil local isTeleporting = false local teleportConnection = nil -- Function to find the closest player local function findClosestPlayer() local closestPlayer = nil local shortestDistance = math.huge for _, otherPlayer in pairs(Players:GetPlayers()) do if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") then local distance = (humanoidRootPart.Position - otherPlayer.Character.HumanoidRootPart.Position).Magnitude if distance < shortestDistance then shortestDistance = distance closestPlayer = otherPlayer end end end return closestPlayer end -- Function to teleport behind a player local function teleportBehind(targetPlayer) if targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("HumanoidRootPart") then local targetHRP = targetPlayer.Character.HumanoidRootPart local offset = Vector3.new(0, 0, 3) -- 3 studs behind local lookDirection = targetHRP.CFrame.LookVector local newPosition = targetHRP.Position - (lookDirection * offset.Z) humanoidRootPart.CFrame = CFrame.new(newPosition, targetHRP.Position) end end -- Input handling UserInputService.InputBegan:Connect(function(input, gameProcessedEvent) if gameProcessedEvent then return end if input.KeyCode == Enum.KeyCode.L then if not isTeleporting then -- Store original position and start teleporting originalPosition = humanoidRootPart.CFrame isTeleporting = true -- Start continuous teleporting teleportConnection = game:GetService("RunService").Heartbeat:Connect(function() local closestPlayer = findClosestPlayer() if closestPlayer then teleportBehind(closestPlayer) end end) else -- Stop teleporting and revert to original position isTeleporting = false if teleportConnection then teleportConnection:Disconnect() teleportConnection = nil end if originalPosition then humanoidRootPart.CFrame = originalPosition originalPosition = nil end end end end) -- Handle character resetting player.CharacterAdded:Connect(function(newCharacter) character = newCharacter humanoidRootPart = character:WaitForChild("HumanoidRootPart") -- Reset teleporting state isTeleporting = false if teleportConnection then teleportConnection:Disconnect() teleportConnection = nil end originalPosition = nil end)