GHOSTOFTCF

Untitled

Aug 12th, 2025 (edited)
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. local UserInputService = game:GetService("UserInputService")
  2. local RunService = game:GetService("RunService")
  3. local Players = game:GetService("Players")
  4. local LocalPlayer = Players.LocalPlayer
  5. local Camera = workspace.CurrentCamera
  6.  
  7. local aimlockEnabled = false
  8. local targetPlayer = nil
  9.  
  10. -- Create ScreenGui (parented to CoreGui so it stays after death)
  11. local ScreenGui = Instance.new("ScreenGui")
  12. ScreenGui.Name = "AimlockNotificationGui"
  13. ScreenGui.Parent = game:GetService("CoreGui")
  14.  
  15. -- Notification Bar
  16. local notifLabel = Instance.new("TextLabel", ScreenGui)
  17. notifLabel.Size = UDim2.new(0, 300, 0, 30)
  18. notifLabel.Position = UDim2.new(0.5, -150, 0, 10)
  19. notifLabel.BackgroundColor3 = Color3.fromRGB(40, 0, 40)
  20. notifLabel.BorderColor3 = Color3.fromRGB(255, 0, 0)
  21. notifLabel.BorderSizePixel = 3
  22. notifLabel.TextColor3 = Color3.fromRGB(255, 50, 50)
  23. notifLabel.Font = Enum.Font.GothamBold
  24. notifLabel.TextSize = 20
  25. notifLabel.TextStrokeTransparency = 0.3
  26. notifLabel.Text = "Press Q To Toggle Aimlock"
  27. notifLabel.Visible = true
  28.  
  29. -- Expand hitbox invisibly for better locking
  30. local function expandHitbox(character)
  31. if character and character:FindFirstChild("HumanoidRootPart") and not character:FindFirstChild("AimlockHitbox") then
  32. local hitbox = Instance.new("Part")
  33. hitbox.Name = "AimlockHitbox"
  34. hitbox.Size = Vector3.new(7, 7, 7) -- bigger than default
  35. hitbox.Transparency = 1 -- invisible
  36. hitbox.Anchored = false
  37. hitbox.CanCollide = false
  38. hitbox.Massless = true
  39. hitbox.CFrame = character.HumanoidRootPart.CFrame
  40. hitbox.Parent = character
  41. local weld = Instance.new("WeldConstraint", hitbox)
  42. weld.Part0 = hitbox
  43. weld.Part1 = character.HumanoidRootPart
  44. end
  45. end
  46.  
  47. -- Function to find closest player to screen center
  48. local function findClosestToCenter()
  49. local closestPlayer, shortestDistance = nil, math.huge
  50. local screenCenter = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
  51.  
  52. for _, player in pairs(Players:GetPlayers()) do
  53. if player ~= LocalPlayer and player.Character and player.Character:FindFirstChild("Humanoid") and player.Character.Humanoid.Health > 0 then
  54. expandHitbox(player.Character)
  55. local hitPart = player.Character:FindFirstChild("AimlockHitbox") or player.Character:FindFirstChild("HumanoidRootPart")
  56. local rootPos, onScreen = Camera:WorldToViewportPoint(hitPart.Position)
  57. if onScreen then
  58. local dist = (Vector2.new(rootPos.X, rootPos.Y) - screenCenter).Magnitude
  59. if dist < shortestDistance then
  60. shortestDistance = dist
  61. closestPlayer = player
  62. end
  63. end
  64. end
  65. end
  66. return closestPlayer
  67. end
  68.  
  69. -- Update notification
  70. local function updateNotification()
  71. if aimlockEnabled then
  72. if targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("Humanoid") then
  73. local hp = math.floor(targetPlayer.Character.Humanoid.Health)
  74. notifLabel.Text = "Aimlock target: " .. targetPlayer.Name .. " (" .. hp .. " HP)"
  75. else
  76. notifLabel.Text = "Aimlocked: No target"
  77. end
  78. else
  79. notifLabel.Text = "Press Q To Toggle Aimlock"
  80. end
  81. end
  82.  
  83. -- Toggle aimlock
  84. local function toggleAimlock()
  85. aimlockEnabled = not aimlockEnabled
  86. if aimlockEnabled then
  87. targetPlayer = findClosestToCenter()
  88. else
  89. targetPlayer = nil
  90. end
  91. updateNotification()
  92. end
  93.  
  94. -- Bind Q to toggle
  95. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  96. if not gameProcessed and input.KeyCode == Enum.KeyCode.Q then
  97. toggleAimlock()
  98. end
  99. end)
  100.  
  101. -- Aim each frame (smooth & hyper-accurate)
  102. RunService.RenderStepped:Connect(function()
  103. if aimlockEnabled and targetPlayer and targetPlayer.Character and targetPlayer.Character:FindFirstChild("AimlockHitbox") then
  104. local hitPart = targetPlayer.Character:FindFirstChild("AimlockHitbox")
  105. local cameraPos = Camera.CFrame.Position
  106. local aimDirection = (hitPart.Position - cameraPos).Unit
  107. -- super accurate locking
  108. Camera.CFrame = Camera.CFrame:Lerp(CFrame.new(cameraPos, cameraPos + aimDirection), 0.4)
  109. updateNotification()
  110. else
  111. if aimlockEnabled then
  112. targetPlayer = findClosestToCenter()
  113. updateNotification()
  114. end
  115. end
  116. end)
  117.  
  118. -- Keep UI & hitbox after respawn
  119. LocalPlayer.CharacterAdded:Connect(function()
  120. task.wait(0.5)
  121. notifLabel.Parent = ScreenGui
  122. updateNotification()
  123. end)
  124.  
  125. -- Keep expanding hitbox for all players
  126. Players.PlayerAdded:Connect(function(plr)
  127. plr.CharacterAdded:Connect(function(char)
  128. task.wait(0.2)
  129. expandHitbox(char)
  130. end)
  131. end)
  132.  
  133. for _, plr in ipairs(Players:GetPlayers()) do
  134. if plr.Character then
  135. expandHitbox(plr.Character)
  136. end
  137. plr.CharacterAdded:Connect(function(char)
  138. task.wait(0.2)
  139. expandHitbox(char)
  140. end)
  141. end
  142.  
Advertisement
Add Comment
Please, Sign In to add comment