-- Instant Camera Lock-On Script (No Prediction, No Lerp) -- Press E to toggle lock-on to the closest enemy's Head near your mouse local Players = game:GetService("Players") local RunService = game:GetService("RunService") local UserInputService = game:GetService("UserInputService") local Workspace = game:GetService("Workspace") local LOCAL_PLAYER = Players.LocalPlayer local CAMERA = Workspace.CurrentCamera -- === CONFIG === local TOGGLE_KEY = Enum.KeyCode.E local MAX_CURSOR_DISTANCE = 150 -- pixels -- ============== local lockOn = false local target = nil local renderConn = nil -- === Helper Functions === local function isEnemy(player) if not player.Team or not LOCAL_PLAYER.Team then return true end return player.Team ~= LOCAL_PLAYER.Team end local function isAlive(player) local char = player.Character local hum = char and char:FindFirstChildOfClass("Humanoid") return hum and hum.Health > 0 end local function getClosestEnemyHead() local mousePos = UserInputService:GetMouseLocation() local closest = nil local closestDistSq = MAX_CURSOR_DISTANCE * MAX_CURSOR_DISTANCE for _, plr in ipairs(Players:GetPlayers()) do if plr ~= LOCAL_PLAYER and isEnemy(plr) and isAlive(plr) then local char = plr.Character local head = char and char:FindFirstChild("Head") if head then local screenPos, onScreen = CAMERA:WorldToViewportPoint(head.Position) if onScreen and screenPos.Z > 0 then local dx = mousePos.X - screenPos.X local dy = mousePos.Y - screenPos.Y local distSq = dx * dx + dy * dy if distSq < closestDistSq then closestDistSq = distSq closest = plr end end end end end return closest end local function clearLock() lockOn = false target = nil if renderConn then renderConn:Disconnect() renderConn = nil end end local function rotateCameraToTarget() if not target or not target.Character then return end local head = target.Character:FindFirstChild("Head") if not head then return end local camPos = CAMERA.CFrame.Position CAMERA.CFrame = CFrame.new(camPos, head.Position) end local function startLock() if renderConn then renderConn:Disconnect() end renderConn = RunService.RenderStepped:Connect(function() if not target or not isAlive(target) or not isEnemy(target) then clearLock() return end rotateCameraToTarget() end) end local function toggleLock() if lockOn then clearLock() else local enemy = getClosestEnemyHead() if enemy then lockOn = true target = enemy startLock() else -- No enemy found end end end -- === Input Bindings === UserInputService.InputBegan:Connect(function(input, gp) if gp then return end if input.KeyCode == TOGGLE_KEY then toggleLock() end end) Players.PlayerRemoving:Connect(function(plr) if plr == target then clearLock() end end) LOCAL_PLAYER.CharacterAdded:Connect(clearLock)