local RunService = game:GetService("RunService") local Stats = game:GetService("Stats") local Players = game:GetService("Players") local UserInputService = game:GetService("UserInputService") local player = Players.LocalPlayer local camera = workspace.CurrentCamera -- Configuration local predictionIntensity = 1.2 local isAiming = false local lockedTarget = nil -- Function to find target local function getClosestPlayer() local closest = nil local shortestDist = math.huge local mousePos = UserInputService:GetMouseLocation() for _, p in pairs(Players:GetPlayers()) do if p ~= player and p.Character and p.Character:FindFirstChild("Head") and p.Character:FindFirstChild("Humanoid") then if p.Character.Humanoid.Health > 0 then local pos, onScreen = camera:WorldToViewportPoint(p.Character.Head.Position) if onScreen then local dist = (Vector2.new(pos.X, pos.Y) - mousePos).Magnitude if dist < shortestDist then closest = p shortestDist = dist end end end end end return closest end local function getPing() local success, ping = pcall(function() return Stats.Network.ServerStatsItem["Data Ping"]:GetValue() / 1000 end) return success and ping or 0.05 end -- UI and Input Setup local function InitializeAimlock() local screenGui = Instance.new("ScreenGui", player:WaitForChild("PlayerGui")) screenGui.Name = "AimLockGui" local toggleButton = Instance.new("TextButton", screenGui) toggleButton.Size = UDim2.new(0, 150, 0, 50) toggleButton.Position = UDim2.new(0.5, -75, 0.8, 0) toggleButton.Text = "Aimlock: OFF" toggleButton.BackgroundColor3 = Color3.fromRGB(200, 0, 0) toggleButton.TextColor3 = Color3.fromRGB(255, 255, 255) local function toggleAim() if not isAiming then lockedTarget = getClosestPlayer() if lockedTarget then isAiming = true toggleButton.Text = "Aimlock: ON (" .. lockedTarget.Name .. ")" toggleButton.BackgroundColor3 = Color3.fromRGB(0, 180, 0) if player.Character and player.Character:FindFirstChild("Humanoid") then player.Character.Humanoid.AutoRotate = false end end else isAiming = false lockedTarget = nil toggleButton.Text = "Aimlock: OFF" toggleButton.BackgroundColor3 = Color3.fromRGB(200, 0, 0) if player.Character and player.Character:FindFirstChild("Humanoid") then player.Character.Humanoid.AutoRotate = true end end end toggleButton.MouseButton1Click:Connect(toggleAim) -- Using a unique name for input to prevent multiple connections UserInputService.InputBegan:Connect(function(input, processed) if processed then return end if input.UserInputType == Enum.UserInputType.MouseButton2 then toggleAim() end end) end -- Main Loop (Kept outside to avoid re-binding issues) RunService:BindToRenderStep("HardLock", Enum.RenderPriority.Camera.Value + 1, function() if isAiming and lockedTarget and lockedTarget.Character then local tHead = lockedTarget.Character:FindFirstChild("Head") local tRoot = lockedTarget.Character:FindFirstChild("HumanoidRootPart") local tHum = lockedTarget.Character:FindFirstChild("Humanoid") local char = player.Character local root = char and char:FindFirstChild("HumanoidRootPart") -- Check if target is still valid/alive if tHead and tRoot and tHum and tHum.Health > 0 and root then local ping = getPing() local predictedPos = tHead.Position + (tRoot.Velocity * ping * predictionIntensity) camera.CFrame = CFrame.lookAt(camera.CFrame.Position, predictedPos) -- Rotate Character local flatLookPos = Vector3.new(predictedPos.X, root.Position.Y, predictedPos.Z) root.CFrame = CFrame.lookAt(root.Position, flatLookPos) else -- Target died or player died, reset state isAiming = false lockedTarget = nil end end end) -- Initial Run InitializeAimlock() -- Note: We don't need CharacterAdded for the UI because ScreenGui.ResetOnSpawn is true by default