Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Aimbot, locks on closest from crosshair, doesn't aim at dead people--
- local Players = game:GetService("Players")
- local LocalPlayer = Players.LocalPlayer
- local Camera = workspace.CurrentCamera
- local RunService = game:GetService("RunService")
- local UserInputService = game:GetService("UserInputService")
- -- Settings
- local LockPart = "Head"
- local MaxDistance = 200 -- Maximum distance to consider for locking (from the crosshair)
- -- State
- local IsAiming = false
- local Highlights = {}
- local CurrentTarget = nil
- -- Utility Functions
- local function CreateHighlight(fillColor)
- local highlight = Instance.new("Highlight")
- highlight.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop -- Ensure visibility through walls
- highlight.FillTransparency = 0.8 -- Transparent fill
- highlight.FillColor = fillColor -- Customizable fill color
- highlight.OutlineTransparency = 0 -- Fully visible outline
- highlight.OutlineColor = Color3.new(1, 1, 1) -- White outline
- highlight.Parent = game.CoreGui -- Parent it so it’s not removed easily
- return highlight
- end
- local function IsOnSameTeam(player)
- -- Check if the player is on the same team as the local player
- return LocalPlayer.Team and player.Team and LocalPlayer.Team == player.Team
- end
- local function IsAlive(player)
- -- Check if the player's character is alive
- local character = player.Character
- if character then
- local humanoid = character:FindFirstChild("Humanoid")
- if humanoid and humanoid.Health > 0 then
- return true
- end
- end
- return false
- end
- local function GetClosestPlayerToCrosshair()
- local closestPlayer = nil
- local shortestDistance = MaxDistance
- for _, player in pairs(Players:GetPlayers()) do
- if player ~= LocalPlayer and not IsOnSameTeam(player) and IsAlive(player) and player.Character and player.Character:FindFirstChild(LockPart) then
- local head = player.Character[LockPart]
- local screenPos, onScreen = Camera:WorldToViewportPoint(head.Position)
- local crosshairPos = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
- local distance = (Vector2.new(screenPos.X, screenPos.Y) - crosshairPos).Magnitude
- if onScreen and distance < shortestDistance then
- shortestDistance = distance
- closestPlayer = player
- end
- end
- end
- return closestPlayer
- end
- local function GetPlayersInRange()
- local playersInRange = {}
- for _, player in pairs(Players:GetPlayers()) do
- if player ~= LocalPlayer and not IsOnSameTeam(player) and IsAlive(player) and player.Character and player.Character:FindFirstChild(LockPart) then
- local head = player.Character[LockPart]
- local screenPos, onScreen = Camera:WorldToViewportPoint(head.Position)
- local crosshairPos = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
- local distance = (Vector2.new(screenPos.X, screenPos.Y) - crosshairPos).Magnitude
- if onScreen and distance <= MaxDistance then
- table.insert(playersInRange, player)
- end
- end
- end
- return playersInRange
- end
- -- Cleanup Old Highlights
- local function ClearHighlights()
- for _, highlight in pairs(Highlights) do
- highlight:Destroy()
- end
- Highlights = {}
- end
- -- Update Highlights
- local function UpdateHighlights(playersInRange)
- ClearHighlights() -- Remove old highlights
- for _, player in ipairs(playersInRange) do
- if player.Character then
- local fillColor = Color3.new(0, 1, 0) -- Green for in-range players
- if player == CurrentTarget then
- fillColor = Color3.new(1, 0, 0) -- Red for the current target
- end
- local highlight = CreateHighlight(fillColor)
- highlight.Adornee = player.Character -- Attach to the player’s character
- table.insert(Highlights, highlight) -- Keep track of the highlight
- end
- end
- end
- -- Input Handling
- UserInputService.InputBegan:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton2 then
- IsAiming = true
- end
- end)
- UserInputService.InputEnded:Connect(function(input)
- if input.UserInputType == Enum.UserInputType.MouseButton2 then
- IsAiming = false
- ClearHighlights() -- Clear all highlights when not aiming
- end
- end)
- -- Update Logic
- RunService.RenderStepped:Connect(function()
- local playersInRange = GetPlayersInRange() -- Get all players in range
- CurrentTarget = nil
- if IsAiming then
- CurrentTarget = GetClosestPlayerToCrosshair() -- Find the closest player to the crosshair
- if CurrentTarget and CurrentTarget.Character and CurrentTarget.Character:FindFirstChild(LockPart) then
- local targetHead = CurrentTarget.Character[LockPart]
- Camera.CFrame = CFrame.new(Camera.CFrame.Position, targetHead.Position) -- Aim at the target
- end
- end
- UpdateHighlights(playersInRange) -- Highlight all players in range
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement