Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- // ==========================================
- -- // SERVICES
- -- // ==========================================
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- local UserInputService = game:GetService("UserInputService")
- local TweenService = game:GetService("TweenService")
- -- // ==========================================
- -- // VARIABLES
- -- // ==========================================
- local LocalPlayer = Players.LocalPlayer
- local Camera = workspace.CurrentCamera
- local enabled = false
- local currentTarget = nil
- local SMOOTHING_FACTOR = 0.3 -- Lower = smoother/slower, Higher = snappier (0.1 to 1.0)
- -- // ==========================================
- -- // GUI CREATION
- -- // ==========================================
- local ScreenGui = Instance.new("ScreenGui")
- local MainFrame = Instance.new("Frame")
- local TitleBar = Instance.new("Frame")
- local TitleText = Instance.new("TextLabel")
- local ToggleButton = Instance.new("TextButton")
- local CloseButton = Instance.new("TextButton")
- -- Configure ScreenGui
- ScreenGui.Name = "CameraLockGUI"
- ScreenGui.ResetOnSpawn = false
- ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
- ScreenGui.Parent = game.CoreGui -- Parent to CoreGui so it persists
- -- Configure Main Frame
- MainFrame.Name = "MainFrame"
- MainFrame.Parent = ScreenGui
- MainFrame.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
- MainFrame.BorderColor3 = Color3.fromRGB(50, 50, 70)
- MainFrame.Position = UDim2.new(0.5, -100, 0.5, -75)
- MainFrame.Size = UDim2.new(0, 200, 0, 150)
- MainFrame.Active = true
- MainFrame.Draggable = true -- Makes the GUI draggable
- -- Configure Title Bar
- TitleBar.Name = "TitleBar"
- TitleBar.Parent = MainFrame
- TitleBar.BackgroundColor3 = Color3.fromRGB(40, 40, 55)
- TitleBar.BorderSizePixel = 0
- TitleBar.Size = UDim2.new(1, 0, 0, 30)
- TitleText.Name = "TitleText"
- TitleText.Parent = TitleBar
- TitleText.BackgroundTransparency = 1
- TitleText.Size = UDim2.new(1, 0, 1, 0)
- TitleText.Font = Enum.Font.GothamBold
- TitleText.Text = "Camera Lock"
- TitleText.TextColor3 = Color3.fromRGB(255, 255, 255)
- TitleText.TextSize = 14
- -- Configure Toggle Button
- ToggleButton.Name = "ToggleButton"
- ToggleButton.Parent = MainFrame
- ToggleButton.BackgroundColor3 = Color3.fromRGB(200, 50, 50) -- Starts Red (Disabled)
- ToggleButton.BorderSizePixel = 0
- ToggleButton.Position = UDim2.new(0.5, -75, 0, 50)
- ToggleButton.Size = UDim2.new(0, 150, 0, 40)
- ToggleButton.Font = Enum.Font.GothamBold
- ToggleButton.Text = "DISABLED"
- ToggleButton.TextColor3 = Color3.fromRGB(255, 255, 255)
- ToggleButton.TextSize = 16
- ToggleButton.AutoButtonColor = true
- -- Configure Close Button
- CloseButton.Name = "CloseButton"
- CloseButton.Parent = TitleBar
- CloseButton.BackgroundTransparency = 1
- CloseButton.Position = UDim2.new(1, -25, 0, 0)
- CloseButton.Size = UDim2.new(0, 25, 0, 30)
- CloseButton.Font = Enum.Font.GothamBold
- CloseButton.Text = "X"
- CloseButton.TextColor3 = Color3.fromRGB(255, 100, 100)
- CloseButton.TextSize = 16
- -- // ==========================================
- -- // GUI LOGIC
- -- // ==========================================
- local function updateToggleButton()
- if enabled then
- ToggleButton.Text = "ENABLED"
- ToggleButton.BackgroundColor3 = Color3.fromRGB(50, 200, 50) -- Green
- else
- ToggleButton.Text = "DISABLED"
- ToggleButton.BackgroundColor3 = Color3.fromRGB(200, 50, 50) -- Red
- currentTarget = nil -- Reset target when disabled
- end
- end
- ToggleButton.MouseButton1Click:Connect(function()
- enabled = not enabled
- updateToggleButton()
- end)
- CloseButton.MouseButton1Click:Connect(function()
- ScreenGui:Destroy()
- end)
- -- // ==========================================
- -- // CORE AIMBOT LOGIC
- -- // ==========================================
- local function getNearestAlivePlayer()
- local nearestPlayer = nil
- local shortestDistance = math.huge
- local myCharacter = LocalPlayer.Character
- local myRoot = myCharacter and myCharacter:FindFirstChild("HumanoidRootPart")
- if not myRoot then return nil end
- for _, player in ipairs(Players:GetPlayers()) do
- if player ~= LocalPlayer and player.Character then
- local targetRoot = player.Character:FindFirstChild("HumanoidRootPart")
- local targetHumanoid = player.Character:FindFirstChild("Humanoid")
- -- Check if target exists, has a humanoid, and is alive
- if targetRoot and targetHumanoid and targetHumanoid.Health > 0 then
- local distance = (myRoot.Position - targetRoot.Position).Magnitude
- if distance < shortestDistance then
- shortestDistance = distance
- nearestPlayer = player
- end
- end
- end
- end
- return nearestPlayer
- end
- -- // ==========================================
- -- // RENDER LOOP (Runs every frame)
- -- // ==========================================
- RunService.RenderStepped:Connect(function()
- -- 1. If disabled, do nothing
- if not enabled then return end
- local myCharacter = LocalPlayer.Character
- if not myCharacter or not myCharacter:FindFirstChild("HumanoidRootPart") then return end
- -- 2. Check if current target died or disconnected
- if currentTarget then
- local targetChar = currentTarget.Character
- local targetHum = targetChar and targetChar:FindFirstChild("Humanoid")
- if not targetHum or targetHum.Health <= 0 then
- currentTarget = nil
- end
- end
- -- 3. Find a new target if we don't have one
- if not currentTarget then
- currentTarget = getNearestAlivePlayer()
- end
- -- 4. Point camera at the target
- if currentTarget and currentTarget.Character then
- local targetAimPart = currentTarget.Character:FindFirstChild("Head")
- or currentTarget.Character:FindFirstChild("HumanoidRootPart")
- if targetAimPart then
- -- Calculate the CFrame we want to look at
- local targetCFrame = CFrame.lookAt(Camera.CFrame.Position, targetAimPart.Position)
- -- Apply Lerp for smooth camera movement (prevents violent first-person jitter)
- Camera.CFrame = Camera.CFrame:Lerp(targetCFrame, SMOOTHING_FACTOR)
- end
- end
- end)
- print("Camera Lock GUI Loaded! Drag the window to move it.")
Advertisement