Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

game:GetService("StarterGui"):SetCore("SendNotification", {Title = "Loaded", Text =

"press Q to auto aim"})

local UserInputService = game:GetService("UserInputService")


local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Camera = workspace.CurrentCamera

-- Settings
local Settings = {
BindKey = "Q" -- Custom Key
}

local isClicking = false

local function getClosestPlayer()


local closestPlayer = nil
local shortestDistance = math.huge

for _, player in pairs(Players:GetPlayers()) do


if player ~= LocalPlayer and player.Character and
player.Character:FindFirstChild("HumanoidRootPart") then
local distance = (player.Character.HumanoidRootPart.Position -
LocalPlayer.Character.HumanoidRootPart.Position).magnitude
if distance < shortestDistance then
closestPlayer = player
shortestDistance = distance
end
end
end

return closestPlayer
end

local function aimAt(target)


if target and target.Character and
target.Character:FindFirstChild("HumanoidRootPart") then
local targetPosition = target.Character.HumanoidRootPart.Position
Camera.CFrame = CFrame.new(Camera.CFrame.Position, targetPosition)

if not isClicking then


isClicking = true
mouse1click()
isClicking = false
end
end
end

UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode[Settings.BindKey:upper()] and not
gameProcessed then
local closestPlayer = getClosestPlayer()
aimAt(closestPlayer)
end
end)

You might also like