Advertisement
A_Xcom

Roblox aimlock / ESP script

Mar 4th, 2025 (edited)
2,630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.56 KB | Source Code | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3. local UserInputService = game:GetService("UserInputService")
  4. local GuiService = game:GetService("GuiService")
  5. local Workspace = game:GetService("Workspace")
  6.  
  7. -- Configuration
  8. local MAX_DISTANCE = 2500 -- Maximum distance to show ESP
  9. local HEALTH_BAR_WIDTH = 50
  10. local HEALTH_BAR_HEIGHT = 5
  11. local AIM_LOCK_KEY = Enum.KeyCode.E
  12.  
  13. -- Anti-Cheat Mitigation
  14. local AIM_SMOOTHNESS = 0.3 -- Lower is smoother, less suspicious
  15. local MIN_AIM_DISTANCE = 10  -- Minimum distance to start aiming
  16. local MAX_AIM_DISTANCE = 500 -- Maximum aim distance
  17.  
  18. -- Settings (will be controlled by GUI)
  19. local Settings = {
  20.     ESPEnabled = true,
  21.     AimLockEnabled = false
  22. }
  23.  
  24. -- Utility function to check line of sight
  25. local function isVisible(origin, target)
  26.     local viewCheck = workspace:FindPartOnRayWithIgnoreList(
  27.         Ray.new(origin, target - origin),
  28.         {Players.LocalPlayer.Character}
  29.     )
  30.     return viewCheck == nil
  31. end
  32.  
  33. -- Create main ScreenGui
  34. local mainGui = Instance.new("ScreenGui")
  35. mainGui.Name = "HackToolGui"
  36. mainGui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")
  37.  
  38. -- Create Toggle GUI (Previous GUI code remains the same)
  39. -- ... [GUI creation code from previous script] ...
  40.  
  41. -- Create ScreenGui to hold ESP elements
  42. local espGui = Instance.new("ScreenGui")
  43. espGui.Name = "ESPGui"
  44. espGui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui")
  45.  
  46. -- Table to store ESP elements
  47. local espElements = {}
  48.  
  49. -- Function to create ESP for a player (Previous implementation)
  50. local function createESP(player)
  51.     if player == Players.LocalPlayer then return end
  52.    
  53.     local nameLabel = Drawing.new("Text")
  54.     nameLabel.Font = Drawing.Fonts.UI
  55.     nameLabel.Size = 13
  56.     nameLabel.Center = true
  57.     nameLabel.Outline = true
  58.    
  59.     local healthBarBackground = Drawing.new("Rectangle")
  60.     healthBarBackground.Filled = true
  61.     healthBarBackground.Color = Color3.new(0, 0, 0)
  62.     healthBarBackground.Transparency = 0.5
  63.    
  64.     local healthBarForeground = Drawing.new("Rectangle")
  65.     healthBarForeground.Filled = true
  66.     healthBarForeground.Color = Color3.new(0, 1, 0)
  67.    
  68.     espElements[player] = {
  69.         nameLabel = nameLabel,
  70.         healthBarBackground = healthBarBackground,
  71.         healthBarForeground = healthBarForeground
  72.     }
  73. end
  74.  
  75. -- Function to update ESP for a player (with minor modifications)
  76. local function updateESP(player, espData)
  77.     -- Skip if ESP is disabled
  78.     if not Settings.ESPEnabled then
  79.         espData.nameLabel.Visible = false
  80.         espData.healthBarBackground.Visible = false
  81.         espData.healthBarForeground.Visible = false
  82.         return
  83.     end
  84.  
  85.     local character = player.Character
  86.     local humanoid = character and character:FindFirstChildOfClass("Humanoid")
  87.     local root = character and character:FindFirstChild("HumanoidRootPart")
  88.    
  89.     if not character or not humanoid or not root then
  90.         espData.nameLabel.Visible = false
  91.         espData.healthBarBackground.Visible = false
  92.         espData.healthBarForeground.Visible = false
  93.         return
  94.     end
  95.    
  96.     local screenPos, onScreen = Workspace.CurrentCamera:WorldToViewportPoint(root.Position)
  97.    
  98.     local localPlayerRoot = Players.LocalPlayer.Character and Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
  99.     local distance = localPlayerRoot and (root.Position - localPlayerRoot.Position).Magnitude or math.huge
  100.    
  101.     if not onScreen or distance > MAX_DISTANCE then
  102.         espData.nameLabel.Visible = false
  103.         espData.healthBarBackground.Visible = false
  104.         espData.healthBarForeground.Visible = false
  105.         return
  106.     end
  107.    
  108.     local teamColor = player.TeamColor or Color3.new(1, 1, 1)
  109.    
  110.     espData.nameLabel.Position = Vector2.new(screenPos.X, screenPos.Y - 20)
  111.     espData.nameLabel.Text = player.Name
  112.     espData.nameLabel.Color = teamColor.Color
  113.     espData.nameLabel.Visible = true
  114.    
  115.     local healthPercentage = humanoid.Health / humanoid.MaxHealth
  116.    
  117.     espData.healthBarBackground.Position = Vector2.new(screenPos.X - HEALTH_BAR_WIDTH/2, screenPos.Y + 10)
  118.     espData.healthBarBackground.Size = Vector2.new(HEALTH_BAR_WIDTH, HEALTH_BAR_HEIGHT)
  119.     espData.healthBarBackground.Visible = true
  120.    
  121.     espData.healthBarForeground.Position = Vector2.new(screenPos.X - HEALTH_BAR_WIDTH/2, screenPos.Y + 10)
  122.     espData.healthBarForeground.Size = Vector2.new(HEALTH_BAR_WIDTH * healthPercentage, HEALTH_BAR_HEIGHT)
  123.     espData.healthBarForeground.Color = Color3.fromRGB(255 * (1 - healthPercentage), 255 * healthPercentage, 0)
  124.     espData.healthBarForeground.Visible = true
  125. end
  126.  
  127. -- Improved Aim Lock Function
  128. local function findNearestPlayerToCrosshair()
  129.     local localPlayer = Players.LocalPlayer
  130.     local camera = Workspace.CurrentCamera
  131.     local localCharacter = localPlayer.Character
  132.    
  133.     if not localCharacter then return nil end
  134.    
  135.     local nearestPlayer = nil
  136.     local shortestDistance = math.huge
  137.    
  138.     for _, player in ipairs(Players:GetPlayers()) do
  139.         -- Skip self, teammates, and players without character
  140.         if player ~= localPlayer and
  141.            player.Team ~= localPlayer.Team and
  142.            player.Character and
  143.            player.Character:FindFirstChild("Head") then
  144.            
  145.             local headPos = player.Character.Head.Position
  146.             local screenPos, onScreen = camera:WorldToScreenPoint(headPos)
  147.            
  148.             if onScreen then
  149.                 -- Calculate distance from screen center
  150.                 local distance = (Vector2.new(screenPos.X, screenPos.Y) -
  151.                     Vector2.new(camera.ViewportSize.X/2, camera.ViewportSize.Y/2)).Magnitude
  152.                
  153.                 -- Additional checks for aim lock
  154.                 local rootPart = player.Character:FindFirstChild("HumanoidRootPart")
  155.                 local distanceToPlayer = (rootPart.Position - localCharacter.HumanoidRootPart.Position).Magnitude
  156.                
  157.                 if distance < shortestDistance and
  158.                    distanceToPlayer >= MIN_AIM_DISTANCE and
  159.                    distanceToPlayer <= MAX_AIM_DISTANCE and
  160.                    isVisible(localCharacter.Head.Position, headPos) then
  161.                     nearestPlayer = player
  162.                     shortestDistance = distance
  163.                 end
  164.             end
  165.         end
  166.     end
  167.    
  168.     return nearestPlayer
  169. end
  170.  
  171. -- Aim Lock Logic
  172. RunService.Heartbeat:Connect(function()
  173.     -- Update ESP for all players
  174.     for player, espData in pairs(espElements) do
  175.         updateESP(player, espData)
  176.     end
  177.    
  178.     -- Aim Lock Logic
  179.     if Settings.AimLockEnabled then
  180.         local nearestPlayer = findNearestPlayerToCrosshair()
  181.        
  182.         if nearestPlayer and nearestPlayer.Character and nearestPlayer.Character:FindFirstChild("Head") then
  183.             local camera = Workspace.CurrentCamera
  184.             local targetHead = nearestPlayer.Character.Head
  185.            
  186.             -- Smooth aim lock with interpolation
  187.             local currentCFrame = camera.CFrame
  188.             local targetCFrame = CFrame.new(currentCFrame.Position, targetHead.Position)
  189.             camera.CFrame = currentCFrame:Lerp(targetCFrame, AIM_SMOOTHNESS)
  190.         end
  191.     end
  192. end)
  193.  
  194. -- Rest of the script remains the same (Player added/removed events, cleanup, etc.)
  195. -- ... [Previous initialization and cleanup code]
  196.  
  197. -- Additional safety measure
  198. if not game:GetService("RunService"):IsStudio() then
  199.     delay(math.random(60, 180), function()
  200.         script:Destroy()
  201.     end)
  202. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement