-- Made by Kason
local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
local camera = workspace.CurrentCamera
local aimbotEnabled = false
local aimKey = Enum.KeyCode.E -- Hold 'E' to lock on
local targetPart = "Head" -- Can be "UpperTorso" or "Head"
-- Function to find the player closest to your mouse/center of screen
local function getClosestPlayer()
local closest = nil
local shortestDistance = math.huge
for _, player in pairs(Players:GetPlayers()) do
if player ~= localPlayer and player.Character and player.Character:FindFirstChild(targetPart) then
-- Check if they are alive
local humanoid = player.Character:FindFirstChild("Humanoid")
if humanoid and humanoid.Health > 0 then
-- Calculate distance from your camera to their head
local screenPos, onScreen = camera:WorldToViewportPoint(player.Character[targetPart].Position)
if onScreen then
-- Calculate distance from the center of the screen
local mousePos = UIS:GetMouseLocation()
local distance = (Vector2.new(screenPos.X, screenPos.Y) - mousePos).Magnitude
if distance < shortestDistance then
closest = player.Character[targetPart]
shortestDistance = distance
end
end
end
end
end
return closest
end
-- Update every frame
RunService.RenderStepped:Connect(function()
if UIS:IsKeyDown(aimKey) then
local target = getClosestPlayer()
if target then
-- This "snaps" your camera to face the target exactly
camera.CFrame = CFrame.new(camera.CFrame.Position, target.Position)
end
end
end)
Comments
No comments yet
Be the first to share your thoughts!