imaRapguy

Untitled

Sep 13th, 2024
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. -- Services
  2. local Players = game:GetService("Players")
  3. local Workspace = game:GetService("Workspace")
  4. local RunService = game:GetService("RunService")
  5. local Player = Players.LocalPlayer
  6. local Camera = Workspace.CurrentCamera
  7.  
  8. -- Aimbot toggle
  9. local aimbotEnabled = false -- Start with aimbot disabled
  10. local currentTarget = nil -- Store the currently targeted player
  11.  
  12. -- Create the GUI for the aimbot toggle
  13. local screenGui = Instance.new("ScreenGui")
  14. screenGui.Name = "AimbotToggle_GUI"
  15. screenGui.Parent = Player:WaitForChild("PlayerGui")
  16. screenGui.ResetOnSpawn = false -- Ensures the GUI doesn't disappear when the player respawns
  17.  
  18. -- Create Aimbot Toggle Button
  19. local aimbotToggleButton = Instance.new("TextButton")
  20. aimbotToggleButton.Size = UDim2.new(0, 120, 0, 50)
  21. aimbotToggleButton.Position = UDim2.new(0, 0, 0, 200)
  22. aimbotToggleButton.Text = "Aimbot: OFF"
  23. aimbotToggleButton.TextColor3 = Color3.fromRGB(255, 255, 255)
  24. aimbotToggleButton.BackgroundColor3 = Color3.fromRGB(0, 0, 0)
  25. aimbotToggleButton.Font = Enum.Font.SourceSans
  26. aimbotToggleButton.TextSize = 18
  27. aimbotToggleButton.Parent = screenGui
  28.  
  29. -- Dragging function for mobile and PC
  30. local dragging = false
  31. local dragStart, startPos
  32.  
  33. local function onDrag(input, gameProcessedEvent)
  34. if not gameProcessedEvent and dragging then
  35. local mousePos = input.Position
  36. local framePos = UDim2.new(0, mousePos.X - (aimbotToggleButton.AbsoluteSize.X / 2), 0, mousePos.Y - (aimbotToggleButton.AbsoluteSize.Y / 2))
  37. aimbotToggleButton.Position = framePos
  38. end
  39. end
  40.  
  41. aimbotToggleButton.InputBegan:Connect(function(input)
  42. if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  43. dragging = true
  44. dragStart = input.Position
  45. startPos = aimbotToggleButton.Position
  46. input.Changed:Connect(function()
  47. if input.UserInputState == Enum.UserInputState.End then
  48. dragging = false
  49. end
  50. end)
  51. end
  52. end)
  53.  
  54. aimbotToggleButton.InputChanged:Connect(onDrag)
  55.  
  56. -- Function to log when aimbot is toggled
  57. local function toggleAimbot()
  58. aimbotEnabled = not aimbotEnabled
  59. if aimbotEnabled then
  60. aimbotToggleButton.Text = "Aimbot: ON"
  61. aimbotToggleButton.BackgroundColor3 = Color3.fromRGB(0, 255, 0) -- Changed color for better visibility
  62. print("Aimbot Enabled")
  63.  
  64. -- Automatically select a new target if not already targeting one
  65. if not currentTarget then
  66. currentTarget = getNearestPlayer()
  67. if currentTarget then
  68. print("Targeting player: " .. currentTarget.Name)
  69. else
  70. print("No target found")
  71. end
  72. end
  73. else
  74. aimbotToggleButton.Text = "Aimbot: OFF"
  75. aimbotToggleButton.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Changed color for better visibility
  76. print("Aimbot Disabled")
  77. currentTarget = nil -- Clear the target when aimbot is disabled
  78. end
  79. end
  80.  
  81. -- Function to find the nearest player
  82. local function getNearestPlayer()
  83. local nearestPlayer = nil
  84. local shortestDistance = math.huge
  85.  
  86. for _, otherPlayer in pairs(Players:GetPlayers()) do
  87. if otherPlayer ~= Player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("Head") then
  88. local head = otherPlayer.Character.Head
  89. local screenPoint, onScreen = Camera:WorldToViewportPoint(head.Position)
  90.  
  91. -- Only consider players whose heads are on screen
  92. if onScreen then
  93. local distance = (Camera.CFrame.Position - head.Position).Magnitude
  94. if distance < shortestDistance then
  95. shortestDistance = distance
  96. nearestPlayer = otherPlayer
  97. end
  98. end
  99. end
  100. end
  101.  
  102. return nearestPlayer
  103. end
  104.  
  105. -- Function to aim at the current target's head
  106. local function aimAtCurrentTarget()
  107. if aimbotEnabled then
  108. if currentTarget and currentTarget.Character then
  109. local head = currentTarget.Character:FindFirstChild("Head")
  110. if head then
  111. -- Move the camera to aim at the current target's head
  112. Camera.CFrame = CFrame.new(Camera.CFrame.Position, head.Position)
  113. print("Aiming at player: " .. currentTarget.Name) -- Log the player being aimed at
  114. else
  115. print("Target's head not found")
  116. currentTarget = getNearestPlayer() -- Update target if head is not found
  117. end
  118. else
  119. print("Current target invalid")
  120. currentTarget = getNearestPlayer() -- Update target if current target is invalid
  121. end
  122. end
  123. end
  124.  
  125. -- Run the aim function every frame
  126. RunService.RenderStepped:Connect(function()
  127. aimAtCurrentTarget()
  128. end)
  129.  
  130. -- Button Connections
  131. aimbotToggleButton.MouseButton1Click:Connect(toggleAimbot)
Advertisement
Add Comment
Please, Sign In to add comment