Advertisement
m9aari

aimlock script

Jun 28th, 2024
428
1
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 1 0
  1. -- Settings
  2. local aimlockRange = 100 -- Adjust the range to your preference
  3. local predictionFactor = 0.13 -- Adjust the prediction factor to your preference
  4.  
  5. -- Create ScreenGui and Button
  6. local gui = Instance.new("ScreenGui")
  7. gui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
  8.  
  9. local button = Instance.new("TextButton")
  10. button.Size = UDim2.new(0, 100, 0, 50)
  11. button.Position = UDim2.new(0.5, -50, 0.5, -25)
  12. button.Text = "Aimlock (OFF)"
  13. button.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Red color
  14. button.TextColor3 = Color3.fromRGB(255, 255, 255)
  15. button.Parent = gui
  16.  
  17. -- Enable Dragging for the Button
  18. local UIS = game:GetService("UserInputService")
  19. local dragging = false
  20. local dragInput, mousePos, framePos
  21.  
  22. button.InputBegan:Connect(function(input)
  23. if input.UserInputType == Enum.UserInputType.MouseButton1 then
  24. dragging = true
  25. mousePos = input.Position
  26. framePos = button.Position
  27.  
  28. input.Changed:Connect(function()
  29. if input.UserInputState == Enum.UserInputState.End then
  30. dragging = false
  31. end
  32. end)
  33. end
  34. end)
  35.  
  36. button.InputChanged:Connect(function(input)
  37. if input.UserInputType == Enum.UserInputType.MouseMovement then
  38. dragInput = input
  39. end
  40. end)
  41.  
  42. UIS.InputChanged:Connect(function(input)
  43. if input == dragInput and dragging then
  44. local delta = input.Position - mousePos
  45. button.Position = UDim2.new(
  46. framePos.X.Scale,
  47. framePos.X.Offset + delta.X,
  48. framePos.Y.Scale,
  49. framePos.Y.Offset + delta.Y
  50. )
  51. end
  52. end)
  53.  
  54. -- Function to toggle aimlock
  55. local aimlockEnabled = false
  56. local lockedPlayer = nil
  57.  
  58. local function toggleAimlock()
  59. aimlockEnabled = not aimlockEnabled
  60. if aimlockEnabled then
  61. button.Text = "Aimlock (ON)"
  62. button.BackgroundColor3 = Color3.fromRGB(0, 255, 0) -- Green color
  63. lockedPlayer = findNearestPlayer() -- Find the nearest player when aimlock is enabled
  64. else
  65. button.Text = "Aimlock (OFF)"
  66. button.BackgroundColor3 = Color3.fromRGB(255, 0, 0) -- Red color
  67. lockedPlayer = nil
  68. end
  69. end
  70.  
  71. -- Toggle aimlock when button is clicked
  72. button.MouseButton1Click:Connect(toggleAimlock)
  73.  
  74. -- Function to find nearest player
  75. local function findNearestPlayer()
  76. local mouse = game.Players.LocalPlayer:GetMouse()
  77. local target = nil
  78. local minDist = aimlockRange
  79.  
  80. for _, player in ipairs(game.Players:GetPlayers()) do
  81. if player ~= game.Players.LocalPlayer and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
  82. local char = player.Character
  83. local dist = (char.HumanoidRootPart.Position - mouse.Hit.p).magnitude
  84. if dist < minDist then
  85. minDist = dist
  86. target = char.HumanoidRootPart
  87. end
  88. end
  89. end
  90.  
  91. return target
  92. end
  93.  
  94. -- Function to handle aimlock rendering with prediction
  95. game:GetService("RunService").RenderStepped:Connect(function()
  96. if aimlockEnabled and lockedPlayer then
  97. local targetPos = lockedPlayer.Position
  98. local targetVelocity = lockedPlayer.Velocity
  99. local predictedPos = targetPos + targetVelocity * predictionFactor
  100. local camera = game.Workspace.CurrentCamera
  101. camera.CFrame = CFrame.new(camera.CFrame.Position, predictedPos)
  102. end
  103. end)
  104.  
  105. -- Handle aimlock behavior with 'F' key
  106. game:GetService("UserInputService").InputBegan:Connect(function(input)
  107. if input.KeyCode == Enum.KeyCode.F then
  108. if aimlockEnabled and lockedPlayer then
  109. lockedPlayer = nil
  110. button.Text = "Aimlock (ON)"
  111. button.BackgroundColor3 = Color3.fromRGB(0, 255, 0) -- Green color
  112. elseif aimlockEnabled then
  113. lockedPlayer = findNearestPlayer()
  114. end
  115. end
  116. end)
  117.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement