Advertisement
WELPLOCKED

Aimlock

Sep 1st, 2024
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. -- Script to run in an executor
  2.  
  3. -- Create the ScreenGui and TextButton if they don't already exist
  4. local player = game.Players.LocalPlayer
  5. local playerGui = player:WaitForChild("PlayerGui")
  6.  
  7. -- Create ScreenGui if it doesn't exist
  8. local screenGui = playerGui:FindFirstChild("CustomScreenGui")
  9. if not screenGui then
  10. screenGui = Instance.new("ScreenGui")
  11. screenGui.Name = "CustomScreenGui"
  12. screenGui.Parent = playerGui
  13. end
  14.  
  15. -- Create the aim-lock button if it doesn't exist
  16. local button = screenGui:FindFirstChild("ToggleButton")
  17. if not button then
  18. button = Instance.new("TextButton")
  19. button.Name = "ToggleButton"
  20. button.Size = UDim2.new(0, 200, 0, 50)
  21. button.Position = UDim2.new(0.5, -100, 0.5, -25)
  22. button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
  23. button.TextColor3 = Color3.fromRGB(255, 255, 255)
  24. button.Text = "Off"
  25. button.Parent = screenGui
  26. end
  27.  
  28. -- Draggable functionality
  29. local dragging = false
  30. local dragInput, startPos, startPosAbs
  31.  
  32. local function onDragBegin(input)
  33. dragging = true
  34. startPos = input.Position
  35. startPosAbs = button.Position
  36. input.Changed:Connect(function()
  37. if input.UserInputState == Enum.UserInputState.End then
  38. dragging = false
  39. end
  40. end)
  41. end
  42.  
  43. local function onDrag(input)
  44. if dragging then
  45. local delta = input.Position - startPos
  46. button.Position = UDim2.new(startPosAbs.X.Scale, startPosAbs.X.Offset + delta.X, startPosAbs.Y.Scale, startPosAbs.Y.Offset + delta.Y)
  47. end
  48. end
  49.  
  50. -- Handle mouse and touch inputs
  51. button.InputBegan:Connect(function(input)
  52. if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
  53. onDragBegin(input)
  54. end
  55. end)
  56.  
  57. button.InputChanged:Connect(function(input)
  58. if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
  59. onDrag(input)
  60. end
  61. end)
  62.  
  63. -- Button states
  64. local isOn = false
  65. local aiming = false
  66.  
  67. -- Function to update the aiming button text and color
  68. local function updateButtonText()
  69. if isOn then
  70. button.Text = "On"
  71. button.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
  72. aiming = true
  73.  
  74. -- Start aiming loop
  75. spawn(function()
  76. while aiming do
  77. local nearestPlayer = nil
  78. local shortestDistance = math.huge
  79.  
  80. for _, otherPlayer in ipairs(game.Players:GetPlayers()) do
  81. if otherPlayer ~= player and otherPlayer.Character and otherPlayer.Character:FindFirstChild("HumanoidRootPart") then
  82. local distance = (player.Character.HumanoidRootPart.Position - otherPlayer.Character.HumanoidRootPart.Position).magnitude
  83. if distance < shortestDistance then
  84. shortestDistance = distance
  85. nearestPlayer = otherPlayer
  86. end
  87. end
  88. end
  89.  
  90. if nearestPlayer and nearestPlayer.Character and nearestPlayer.Character:FindFirstChild("HumanoidRootPart") then
  91. local targetPosition = nearestPlayer.Character.HumanoidRootPart.Position
  92. local camera = workspace.CurrentCamera
  93.  
  94. -- Default aim-lock behavior
  95. camera.CFrame = CFrame.lookAt(camera.CFrame.Position, targetPosition)
  96. end
  97.  
  98. wait(0.1) -- Update every 0.1 seconds
  99. end
  100. end)
  101. else
  102. button.Text = "Off"
  103. button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
  104. aiming = false
  105. end
  106. end
  107.  
  108. -- Toggle aiming button state when clicked
  109. button.MouseButton1Click:Connect(function()
  110. isOn = not isOn
  111. updateButtonText()
  112. end)
  113.  
  114. -- Initial button text update
  115. updateButtonText()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement