Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local UserInputService = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local Players = game:GetService("Players")
- local LocalPlayer = Players.LocalPlayer
- local Camera = workspace.CurrentCamera
- local aimlockEnabled = false
- local targetPlayer = nil
- -- Create ScreenGui (parented to CoreGui so it stays after death)
- local ScreenGui = Instance.new("ScreenGui")
- ScreenGui.Name = "AimlockNotificationGui"
- ScreenGui.Parent = game:GetService("CoreGui")
- -- Notification Bar
- local notifLabel = Instance.new("TextLabel", ScreenGui)
- notifLabel.Size = UDim2.new(0, 300, 0, 30)
- notifLabel.Position = UDim2.new(0.5, -150, 0, 10)
- notifLabel.BackgroundColor3 = Color3.fromRGB(40, 0, 40)
- notifLabel.BorderColor3 = Color3.fromRGB(255, 0, 0)
- notifLabel.BorderSizePixel = 3
- notifLabel.TextColor3 = Color3.fromRGB(255, 50, 50)
- notifLabel.Font = Enum.Font.GothamBold
- notifLabel.TextSize = 20
- notifLabel.TextStrokeTransparency = 0.3
- notifLabel.Text = "Press Q To Toggle Aimlock"
- notifLabel.Visible = true
- -- Expand hitbox invisibly for better locking
- local function expandHitbox(character)
- if character and character:FindFirstChild("HumanoidRootPart") and not character:FindFirstChild("AimlockHitbox") then
- local hitbox = Instance.new("Part")
- hitbox.Name = "AimlockHitbox"
- hitbox.Size = Vector3.new(7, 7, 7) -- bigger than default
- hitbox.Transparency = 1 -- invisible
- hitbox.Anchored = false
- hitbox.CanCollide = false
- hitbox.Massless = true
- hitbox.CFrame = character.HumanoidRootPart.CFrame
- hitbox.Parent = character
- local weld = Instance.new("WeldConstraint", hitbox)
- weld.Part0 = hitbox
- weld.Part1 = character.HumanoidRootPart
- end
- end
- -- Function to find closest player to screen center
- local function findClosestToCenter()
- local closestPlayer, shortestDistance = nil, math.huge
- local screenCenter = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
- for _, player in pairs(Players:GetPlayers()) do
- if player ~= LocalPlayer and player.Character and player.Character:FindFirstChild("Humanoid") and player.Character.Humanoid.Health > 0 then
- expandHitbox(player.Character)
- local hitPart = player.Character:FindFirstChild("AimlockHitbox") or player.Character:FindFirstChild("HumanoidRootPart")
- local rootPos, onScreen = Camera:WorldToViewportPoint(hitPart.Position)
- if onScreen then
- local dist = (Vector2.new(rootPos.X, rootPos.Y) - screenCenter).Magnitude
- if dist < shortestDistance then
- shortestDistance = dist
- closestPlayer = player
- end
- end
- end
- end
- return closestPlayer
- end
- -- Update notification
- local function updateNotification()
- if aimlockEnabled then
- if targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("Humanoid") then
- local hp = math.floor(targetPlayer.Character.Humanoid.Health)
- notifLabel.Text = "Aimlock target: " .. targetPlayer.Name .. " (" .. hp .. " HP)"
- else
- notifLabel.Text = "Aimlocked: No target"
- end
- else
- notifLabel.Text = "Press Q To Toggle Aimlock"
- end
- end
- -- Toggle aimlock
- local function toggleAimlock()
- aimlockEnabled = not aimlockEnabled
- if aimlockEnabled then
- targetPlayer = findClosestToCenter()
- else
- targetPlayer = nil
- end
- updateNotification()
- end
- -- Bind Q to toggle
- UserInputService.InputBegan:Connect(function(input, gameProcessed)
- if not gameProcessed and input.KeyCode == Enum.KeyCode.Q then
- toggleAimlock()
- end
- end)
- -- Aim each frame (smooth & hyper-accurate)
- RunService.RenderStepped:Connect(function()
- if aimlockEnabled and targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("AimlockHitbox") then
- local hitPart = targetPlayer.Character:FindFirstChild("AimlockHitbox")
- local cameraPos = Camera.CFrame.Position
- local aimDirection = (hitPart.Position - cameraPos).Unit
- -- super accurate locking
- Camera.CFrame = Camera.CFrame:Lerp(CFrame.new(cameraPos, cameraPos + aimDirection), 0.4)
- updateNotification()
- else
- if aimlockEnabled then
- targetPlayer = findClosestToCenter()
- updateNotification()
- end
- end
- end)
- -- Keep UI & hitbox after respawn
- LocalPlayer.CharacterAdded:Connect(function()
- task.wait(0.5)
- notifLabel.Parent = ScreenGui
- updateNotification()
- end)
- -- Keep expanding hitbox for all players
- Players.PlayerAdded:Connect(function(plr)
- plr.CharacterAdded:Connect(function(char)
- task.wait(0.2)
- expandHitbox(char)
- end)
- end)
- for _, plr in ipairs(Players:GetPlayers()) do
- if plr.Character then
- expandHitbox(plr.Character)
- end
- plr.CharacterAdded:Connect(function(char)
- task.wait(0.2)
- expandHitbox(char)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment