Advertisement
himydude

Untitled

May 4th, 2024
1,021
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.16 KB | Gaming | 0 0
  1. -- Create a ScreenGui for the buttons
  2. local gui = Instance.new("ScreenGui")
  3. gui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
  4.  
  5. -- Create a TextButton for aiming
  6. local aimButton = Instance.new("TextButton")
  7. aimButton.Text = "Aim"
  8. aimButton.Size = UDim2.new(0, 60, 0, 30)
  9. aimButton.Position = UDim2.new(0.5, -90, 0, 10)
  10. aimButton.Parent = gui
  11.  
  12. -- Create a TextButton for the "Bringer" button
  13. local bringerButton = Instance.new("TextButton")
  14. bringerButton.Text = "Bringer Off"
  15. bringerButton.Size = UDim2.new(0, 100, 0, 30)
  16. bringerButton.Position = UDim2.new(0.5, 30, 0, 10) -- Adjust position as needed
  17. bringerButton.Parent = gui
  18.  
  19. -- Variable to keep track of whether aiming is active
  20. local aimingActive = false
  21.  
  22. -- Variable to keep track of whether the bringer is active
  23. local bringerActive = false
  24.  
  25. -- Function to make the camera look at the nearest player's head from the opposite team
  26. local function aimAtNearestOpponent()
  27.     local player = game.Players.LocalPlayer
  28.     local character = player.Character
  29.     if character then
  30.         local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  31.         if humanoidRootPart then
  32.             local nearestPlayer = nil
  33.             local shortestDistance = math.huge
  34.             for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
  35.                 if otherPlayer.Team ~= player.Team then -- Only consider players from the opposite team
  36.                     local otherCharacter = otherPlayer.Character
  37.                     if otherCharacter then
  38.                         local otherHead = otherCharacter:FindFirstChild("Head")
  39.                         if otherHead then
  40.                             -- Check if the player is visible to the user
  41.                             local ray = Ray.new(humanoidRootPart.Position, (otherHead.Position - humanoidRootPart.Position).Unit * 1000)
  42.                             local part, position = game.Workspace:FindPartOnRay(ray, player.Character, false, true)
  43.                             if part and part:IsDescendantOf(otherCharacter) then
  44.                                 local distance = (humanoidRootPart.Position - otherHead.Position).Magnitude
  45.                                 if distance < shortestDistance then
  46.                                     nearestPlayer = otherPlayer
  47.                                     shortestDistance = distance
  48.                                 end
  49.                             end
  50.                         end
  51.                     end
  52.                 end
  53.             end
  54.             if nearestPlayer then
  55.                 local nearestCharacter = nearestPlayer.Character
  56.                 if nearestCharacter then
  57.                     local nearestHead = nearestCharacter:FindFirstChild("Head")
  58.                     if nearestHead then
  59.                         game.Workspace.CurrentCamera.CFrame = CFrame.new(game.Workspace.CurrentCamera.CFrame.Position, nearestHead.Position)
  60.                     end
  61.                 end
  62.             end
  63.         end
  64.     end
  65. end
  66.  
  67. -- Function to toggle aiming on/off when the button is clicked
  68. local function toggleAim()
  69.     aimingActive = not aimingActive
  70.     if aimingActive then
  71.         aimButton.Text = "Stop Aim"
  72.         -- Start aiming
  73.         while aimingActive do
  74.             aimAtNearestOpponent()
  75.             wait()
  76.         end
  77.     else
  78.         aimButton.Text = "Aim"
  79.         -- Stop aiming
  80.     end
  81. end
  82.  
  83. -- Function to toggle aiming on/off when 'x' key is pressed
  84. local function toggleAimWithKey()
  85.     toggleAim() -- Toggle aiming when 'x' key is pressed
  86. end
  87.  
  88. -- Connect the 'x' key press event to the toggleAimWithKey function
  89. game:GetService("UserInputService").InputBegan:Connect(function(input)
  90.     if input.KeyCode == Enum.KeyCode.X then
  91.         toggleAimWithKey()
  92.     end
  93. end)
  94.  
  95. -- Function to toggle the bringer on/off when the button is clicked
  96. local function toggleBringer()
  97.     bringerActive = not bringerActive
  98.     if bringerActive then
  99.         bringerButton.Text = "Bringer On"
  100.         -- Start bringing user to the nearest player
  101.         while bringerActive do
  102.             local player = game.Players.LocalPlayer
  103.             local character = player.Character
  104.             if character then
  105.                 local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  106.                 if humanoidRootPart then
  107.                     local nearestPlayer = nil
  108.                     local shortestDistance = math.huge
  109.                     for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
  110.                         if otherPlayer.Team ~= player.Team then -- Only consider players from the opposite team
  111.                             local otherCharacter = otherPlayer.Character
  112.                             if otherCharacter then
  113.                                 local otherHead = otherCharacter:FindFirstChild("Head")
  114.                                 if otherHead then
  115.                                     local distance = (humanoidRootPart.Position - otherHead.Position).Magnitude
  116.                                     if distance < shortestDistance then
  117.                                         nearestPlayer = otherPlayer
  118.                                         shortestDistance = distance
  119.                                     end
  120.                                 end
  121.                             end
  122.                         end
  123.                     end
  124.                     if nearestPlayer then
  125.                         local nearestCharacter = nearestPlayer.Character
  126.                         if nearestCharacter then
  127.                             local nearestHead = nearestCharacter:FindFirstChild("Head")
  128.                             if nearestHead then
  129.                                 humanoidRootPart.CFrame = CFrame.new(nearestHead.Position)
  130.                             end
  131.                         end
  132.                     end
  133.                 end
  134.             end
  135.             wait()
  136.         end
  137.     else
  138.         bringerButton.Text = "Bringer Off"
  139.         -- Stop bringing user to nearest player
  140.     end
  141. end
  142.  
  143. -- Connect button click events to their respective functions
  144. aimButton.MouseButton1Click:Connect(toggleAim)
  145. bringerButton.MouseButton1Click:Connect(toggleBringer)
  146.  
Tags: Roblox Hacks
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement