HaloJnZ

Untitled

May 25th, 2024 (edited)
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3. local UserInputService = game:GetService("UserInputService")
  4.  
  5. local currentPlayer = Players.LocalPlayer
  6. local camera = workspace.CurrentCamera
  7.  
  8. local aimbotEnabled = false
  9. local maxFOV = 70 -- in degrees
  10. local FOVCircleRadius = 300 -- pixel radius of FOV circle
  11. local smoothing = 0.2
  12.  
  13. -- Drawing the FOV circle
  14. local FOVCircle = Drawing.new("Circle")
  15. FOVCircle.Radius = FOVCircleRadius
  16. FOVCircle.Thickness = 2
  17. FOVCircle.Transparency = 1
  18. FOVCircle.Color = Color3.fromRGB(255, 0, 0)
  19. FOVCircle.Filled = false
  20.  
  21. -- Toggle aimbot with E key
  22. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  23. if not gameProcessed and input.KeyCode == Enum.KeyCode.E then
  24. aimbotEnabled = not aimbotEnabled
  25. print("Aimbot " .. (aimbotEnabled and "Enabled" or "Disabled"))
  26. end
  27. end)
  28.  
  29. -- Update circle position and size every frame
  30. RunService.RenderStepped:Connect(function()
  31. local viewportSize = camera.ViewportSize
  32. FOVCircle.Position = Vector2.new(viewportSize.X / 2, viewportSize.Y / 2)
  33. FOVCircle.Visible = aimbotEnabled
  34. end)
  35.  
  36. -- Check if world position is in FOV
  37. local function isInFOV(position)
  38. local screenPoint, onScreen = camera:WorldToViewportPoint(position)
  39. if onScreen then
  40. local cameraDirection = camera.CFrame.LookVector
  41. local directionToTarget = (position - camera.CFrame.Position).Unit
  42. local angle = math.deg(math.acos(cameraDirection:Dot(directionToTarget)))
  43. return angle <= maxFOV / 2
  44. end
  45. return false
  46. end
  47.  
  48. -- Find closest enemy within FOV
  49. local function getClosestEnemyPlayer()
  50. local closestEnemy
  51. local shortestDistance = math.huge
  52.  
  53. for _, player in ipairs(Players:GetPlayers()) do
  54. if player ~= currentPlayer and player.Character and currentPlayer.Character then
  55. local isEnemy = not currentPlayer.Team or player.Team ~= currentPlayer.Team
  56. local targetRoot = player.Character:FindFirstChild("HumanoidRootPart")
  57. local myRoot = currentPlayer.Character:FindFirstChild("HumanoidRootPart")
  58.  
  59. if isEnemy and targetRoot and myRoot then
  60. if isInFOV(targetRoot.Position) then
  61. local distance = (targetRoot.Position - myRoot.Position).Magnitude
  62. if distance < shortestDistance then
  63. shortestDistance = distance
  64. closestEnemy = player
  65. end
  66. end
  67. end
  68. end
  69. end
  70.  
  71. return closestEnemy
  72. end
  73.  
  74. -- Aim at the closest enemy
  75. local function aimAtClosestEnemyPlayer()
  76. if not aimbotEnabled then return end
  77.  
  78. local target = getClosestEnemyPlayer()
  79. if target and target.Character and target.Character:FindFirstChild("HumanoidRootPart") then
  80. local targetPos = target.Character.HumanoidRootPart.Position
  81. camera.CFrame = camera.CFrame:Lerp(CFrame.new(camera.CFrame.Position, targetPos), smoothing)
  82. end
  83. end
  84.  
  85. -- Run every frame
  86. RunService.RenderStepped:Connect(aimAtClosestEnemyPlayer)
Tags: lua scripting
Advertisement
Add Comment
Please, Sign In to add comment