getgenv().settings = {
["smooth"] = true; -- whether or not to make the aimbot snap to targets smoothly
["aimPart"] = "Head"; -- what part of the target to aim at ("Head" or "RootPart")
["aimKey"] = "X"; -- what key to press to aim at a target
}
getgenv().aiming = false
if not highlight then
getgenv().highlight = Instance.new("Highlight")
highlight.Enabled = false
highlight.FillColor = Color3.fromRGB(200, 200, 200)
highlight.FillTransparency = 0.5
highlight.OutlineColor = Color3.fromRGB(255, 255, 255)
highlight.OutlineTransparency = 1
highlight.Parent = game:GetService("CoreGui")
end
if inputBegan then
print("reset")
inputBegan:Disconnect()
inputBegan = nil
else
print("loaded")
end
if inputEnded then
inputEnded:Disconnect()
inputEnded = nil
end
if renderStepped then
renderStepped:Disconnect()
renderStepped = nil
end
local userInputService = game:GetService("UserInputService")
local tweenService = game:GetService("TweenService")
local runService = game:GetService("RunService")
local players = game:GetService("Players")
local plr = players.LocalPlayer
local mouse = plr:GetMouse()
local currentTarget = nil
local function getCamera()
return workspace.CurrentCamera
end
local function getMousePos()
return userInputService:GetMouseLocation()
end
local function getCharacter(player)
player = player or plr
return player.Character
end
local function getMouseTarget()
return mouse.Target
end
local function getRootPart(player)
player = player or plr
return getCharacter(player):WaitForChild("HumanoidRootPart")
end
local function getHead(player)
player = player or plr
return getCharacter(player):WaitForChild("Head")
end
local function flatten(vector)
return Vector3.new(vector.X, 0, vector.Z)
end
local function getAimPart(target)
if settings["aimPart"] == "Head" then
return getHead(target)
else
return getRootPart(target)
end
end
local function isVisible(target)
local camera = getCamera()
local targetRoot = getRootPart(target)
local _, visible = camera:WorldToScreenPoint(targetRoot.Position)
return visible
end
local function getDistanceOnScreen(target)
local mousePos = getMousePos()
local camera = getCamera()
local targetRoot = getRootPart(target)
local targetPosV3 = camera:WorldToScreenPoint(targetRoot.Position)
local targetPosV2 = Vector2.new(targetPosV3.X, targetPosV3.Y)
return (mousePos - targetPosV2).Magnitude
end
local function getPointOnScreen(position)
local camera = getCamera()
local result = camera:WorldToScreenPoint(position)
return Vector2.new(result.X, result.Y)
end
local function tweenCamera(position)
local camera = getCamera()
local plrHead = getHead()
local newCFrame = CFrame.new(plrHead.Position, position)
local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Circular, Enum.EasingDirection.In)
local tween = tweenService:Create(camera, tweenInfo, {CFrame = newCFrame})
tween:Play()
tween.Completed:Wait()
end
local function snapCamera(position)
local camera = getCamera()
local plrHead = getHead()
local newCFrame = CFrame.new(plrHead.Position, position)
camera.CFrame = newCFrame
end
local function aimAt(target, forceTween)
local character = getCharacter(target)
local visible = isVisible(target)
if character then
if not visible then
return true
end
local aimPart = getAimPart(target)
local aimPos = aimPart.Position
local distance = getDistanceOnScreen(target)
if forceTween then
tweenCamera(aimPos)
else
snapCamera(aimPos)
end
return false
end
return true
end
local function getTarget()
local distance = math.huge
local target = nil
for _, tempTarget in next, players:GetPlayers() do
local targetChar = getCharacter(tempTarget)
if tempTarget == plr then
continue
end
if targetChar and isVisible(tempTarget) then
local aimPart = getAimPart(tempTarget)
local targetPos = getPointOnScreen(aimPart.Position)
local mousePos = getMousePos()
local tempDist = (mousePos - targetPos).Magnitude
if tempDist < distance then
distance = tempDist
target = tempTarget
end
end
end
return target
end
getgenv().inputBegan = userInputService.InputBegan:Connect(function(key, gpe)
if gpe then
return
end
if key.KeyCode == Enum.KeyCode[settings["aimKey"]] then
local target = getTarget()
if target then
local forceTween = true
aiming = true
while task.wait() do
local character = getCharacter(target)
if character then
currentTarget = target
highlight.Adornee = character
highlight.Enabled = true
forceTween = aimAt(target, forceTween)
else
aiming = false
end
if not aiming then
currentTarget = nil
highlight.Enabled = false
break
end
end
else
aiming = false
end
end
end)
getgenv().inputEnded = userInputService.InputEnded:Connect(function(key, gpe)
if gpe then
return
end
if key.KeyCode == Enum.KeyCode[settings["aimKey"]] then
aiming = false
end
end)
getgenv().renderStepped = runService.RenderStepped:Connect(function()
if currentTarget then
local mouseTarget = getMouseTarget()
if mouseTarget then
local character = (mouseTarget.Parent:IsA("Model") and mouseTarget.Parent) or mouseTarget.Parent.Parent
local target = players:GetPlayerFromCharacter(character)
if target then
if target == currentTarget then
highlight.FillColor = Color3.fromRGB(0, 200, 0)
highlight.OutlineColor = Color3.fromRGB(0, 255, 0)
mouse1click()
task.wait()
highlight.FillColor = Color3.fromRGB(200, 200, 200)
highlight.OutlineColor = Color3.fromRGB(255, 255, 255)
end
end
end
end
end)