Advertisement
Cra-Z-Gaming

Aimbot W/filter

Nov 25th, 2024 (edited)
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.12 KB | Gaming | 0 0
  1. --Aimbot, locks on closest from crosshair, doesn't aim at dead people--
  2.  
  3. local Players = game:GetService("Players")
  4. local LocalPlayer = Players.LocalPlayer
  5. local Camera = workspace.CurrentCamera
  6. local RunService = game:GetService("RunService")
  7. local UserInputService = game:GetService("UserInputService")
  8.  
  9. -- Settings
  10. local LockPart = "Head"
  11. local MaxDistance = 200 -- Maximum distance to consider for locking (from the crosshair)
  12.  
  13. -- State
  14. local IsAiming = false
  15. local Highlights = {}
  16. local CurrentTarget = nil
  17.  
  18. -- Utility Functions
  19. local function CreateHighlight(fillColor)
  20.     local highlight = Instance.new("Highlight")
  21.     highlight.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop -- Ensure visibility through walls
  22.     highlight.FillTransparency = 0.8 -- Transparent fill
  23.     highlight.FillColor = fillColor -- Customizable fill color
  24.     highlight.OutlineTransparency = 0 -- Fully visible outline
  25.     highlight.OutlineColor = Color3.new(1, 1, 1) -- White outline
  26.     highlight.Parent = game.CoreGui -- Parent it so it’s not removed easily
  27.     return highlight
  28. end
  29.  
  30. local function IsOnSameTeam(player)
  31.     -- Check if the player is on the same team as the local player
  32.     return LocalPlayer.Team and player.Team and LocalPlayer.Team == player.Team
  33. end
  34.  
  35. local function IsAlive(player)
  36.     -- Check if the player's character is alive
  37.     local character = player.Character
  38.     if character then
  39.         local humanoid = character:FindFirstChild("Humanoid")
  40.         if humanoid and humanoid.Health > 0 then
  41.             return true
  42.         end
  43.     end
  44.     return false
  45. end
  46.  
  47. local function GetClosestPlayerToCrosshair()
  48.     local closestPlayer = nil
  49.     local shortestDistance = MaxDistance
  50.  
  51.     for _, player in pairs(Players:GetPlayers()) do
  52.         if player ~= LocalPlayer and not IsOnSameTeam(player) and IsAlive(player) and player.Character and player.Character:FindFirstChild(LockPart) then
  53.             local head = player.Character[LockPart]
  54.             local screenPos, onScreen = Camera:WorldToViewportPoint(head.Position)
  55.             local crosshairPos = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
  56.             local distance = (Vector2.new(screenPos.X, screenPos.Y) - crosshairPos).Magnitude
  57.  
  58.             if onScreen and distance < shortestDistance then
  59.                 shortestDistance = distance
  60.                 closestPlayer = player
  61.             end
  62.         end
  63.     end
  64.  
  65.     return closestPlayer
  66. end
  67.  
  68. local function GetPlayersInRange()
  69.     local playersInRange = {}
  70.  
  71.     for _, player in pairs(Players:GetPlayers()) do
  72.         if player ~= LocalPlayer and not IsOnSameTeam(player) and IsAlive(player) and player.Character and player.Character:FindFirstChild(LockPart) then
  73.             local head = player.Character[LockPart]
  74.             local screenPos, onScreen = Camera:WorldToViewportPoint(head.Position)
  75.             local crosshairPos = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
  76.             local distance = (Vector2.new(screenPos.X, screenPos.Y) - crosshairPos).Magnitude
  77.  
  78.             if onScreen and distance <= MaxDistance then
  79.                 table.insert(playersInRange, player)
  80.             end
  81.         end
  82.     end
  83.  
  84.     return playersInRange
  85. end
  86.  
  87. -- Cleanup Old Highlights
  88. local function ClearHighlights()
  89.     for _, highlight in pairs(Highlights) do
  90.         highlight:Destroy()
  91.     end
  92.     Highlights = {}
  93. end
  94.  
  95. -- Update Highlights
  96. local function UpdateHighlights(playersInRange)
  97.     ClearHighlights() -- Remove old highlights
  98.  
  99.     for _, player in ipairs(playersInRange) do
  100.         if player.Character then
  101.             local fillColor = Color3.new(0, 1, 0) -- Green for in-range players
  102.             if player == CurrentTarget then
  103.                 fillColor = Color3.new(1, 0, 0) -- Red for the current target
  104.             end
  105.  
  106.             local highlight = CreateHighlight(fillColor)
  107.             highlight.Adornee = player.Character -- Attach to the player’s character
  108.             table.insert(Highlights, highlight) -- Keep track of the highlight
  109.         end
  110.     end
  111. end
  112.  
  113. -- Input Handling
  114. UserInputService.InputBegan:Connect(function(input)
  115.     if input.UserInputType == Enum.UserInputType.MouseButton2 then
  116.         IsAiming = true
  117.     end
  118. end)
  119.  
  120. UserInputService.InputEnded:Connect(function(input)
  121.     if input.UserInputType == Enum.UserInputType.MouseButton2 then
  122.         IsAiming = false
  123.         ClearHighlights() -- Clear all highlights when not aiming
  124.     end
  125. end)
  126.  
  127. -- Update Logic
  128. RunService.RenderStepped:Connect(function()
  129.     local playersInRange = GetPlayersInRange() -- Get all players in range
  130.     CurrentTarget = nil
  131.  
  132.     if IsAiming then
  133.         CurrentTarget = GetClosestPlayerToCrosshair() -- Find the closest player to the crosshair
  134.         if CurrentTarget and CurrentTarget.Character and CurrentTarget.Character:FindFirstChild(LockPart) then
  135.             local targetHead = CurrentTarget.Character[LockPart]
  136.             Camera.CFrame = CFrame.new(Camera.CFrame.Position, targetHead.Position) -- Aim at the target
  137.         end
  138.     end
  139.  
  140.     UpdateHighlights(playersInRange) -- Highlight all players in range
  141. end)
  142.  
Tags: Aimbot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement