Advertisement
Cra-Z-Gaming

AimBot (By: ChatGPT)

Sep 17th, 2024 (edited)
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. -- Services
  2. local Players = game:GetService("Players")
  3. local RunService = game:GetService("RunService")
  4. local UserInputService = game:GetService("UserInputService")
  5. local Camera = workspace.CurrentCamera
  6.  
  7. -- Check if a player has a ForceField
  8. local function hasForceField(player)
  9.     if player.Character then
  10.         return player.Character:FindFirstChildOfClass("ForceField") ~= nil
  11.     end
  12.     return false
  13. end
  14.  
  15. -- Find the closest player to the local player
  16. local function findClosestPlayer()
  17.     local localPlayer = Players.LocalPlayer
  18.     local closestPlayer = nil
  19.     local shortestDistance = math.huge
  20.  
  21.     for _, player in ipairs(Players:GetPlayers()) do
  22.         if player ~= localPlayer and player.Character and player.Character:FindFirstChild("Head") then
  23.             -- Skip players with ForceField
  24.             if not hasForceField(player) then
  25.                 local head = player.Character.Head
  26.                 local distance = (localPlayer.Character.HumanoidRootPart.Position - head.Position).magnitude
  27.  
  28.                 if distance < shortestDistance then
  29.                     shortestDistance = distance
  30.                     closestPlayer = player
  31.                 end
  32.             end
  33.         end
  34.     end
  35.  
  36.     return closestPlayer
  37. end
  38.  
  39. -- Function to make the camera aim at the closest player's head
  40. local function aimCameraAtClosestPlayer()
  41.     RunService.RenderStepped:Connect(function()
  42.         if UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton2) then  -- Check if right mouse button is held down
  43.             local closestPlayer = findClosestPlayer()
  44.  
  45.             if closestPlayer and closestPlayer.Character and closestPlayer.Character:FindFirstChild("Head") then
  46.                 local head = closestPlayer.Character.Head
  47.                 -- Adjust the camera to look at the target's head
  48.                 Camera.CFrame = CFrame.new(Camera.CFrame.Position, head.Position)
  49.             end
  50.         end
  51.     end)
  52. end
  53.  
  54. -- Initialize the aim feature
  55. aimCameraAtClosestPlayer()
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement