Advertisement
Guest User

Silent Aim Script

a guest
Oct 3rd, 2024
2,460
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 1
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3. local UserInputService = game:GetService("UserInputService")
  4. local Camera = workspace.CurrentCamera
  5. local LocalPlayer = Players.LocalPlayer
  6.  
  7. -- Settings
  8. local FOVRadius = 200 -- Adjust the radius of the FOV circle
  9. local ThirdPersonThreshold = 5 -- Adjust this value to determine third-person view threshold
  10. local FOVCircle = Drawing.new("Circle")
  11. FOVCircle.Radius = FOVRadius
  12. FOVCircle.Color = Color3.fromRGB(255, 255, 255)
  13. FOVCircle.Thickness = 2
  14. FOVCircle.Transparency = 1
  15. FOVCircle.Filled = false
  16.  
  17. -- Silent Aim
  18. local function isVisible(target)
  19. local character = target.Character
  20. if character and character:FindFirstChild("Head") then
  21. local ray = Ray.new(Camera.CFrame.Position, (character.Head.Position - Camera.CFrame.Position).unit * 500)
  22. local hit = workspace:FindPartOnRay(ray, LocalPlayer.Character)
  23. return hit and hit:IsDescendantOf(character)
  24. end
  25. return false
  26. end
  27.  
  28. local function getNearestPlayer()
  29. local nearestPlayer = nil
  30. local shortestDistance = FOVRadius
  31.  
  32. for _, player in pairs(Players:GetPlayers()) do
  33. if player ~= LocalPlayer and player.Team ~= LocalPlayer.Team then
  34. local character = player.Character
  35. local head = character and character:FindFirstChild("Head")
  36.  
  37. if head then
  38. local headPosition, onScreen = Camera:WorldToViewportPoint(head.Position)
  39. local mousePosition = UserInputService:GetMouseLocation()
  40. local distanceFromMouse = (Vector2.new(headPosition.X, headPosition.Y) - mousePosition).Magnitude
  41.  
  42. if onScreen and distanceFromMouse < shortestDistance and isVisible(player) then
  43. nearestPlayer = player
  44. shortestDistance = distanceFromMouse
  45. end
  46. end
  47. end
  48. end
  49.  
  50. return nearestPlayer
  51. end
  52.  
  53. -- Check if the player is in third-person view
  54. local function isThirdPerson()
  55. local character = LocalPlayer.Character
  56. if character and character:FindFirstChild("Head") then
  57. local distance = (Camera.CFrame.Position - character.Head.Position).Magnitude
  58. return distance > ThirdPersonThreshold
  59. end
  60. return false
  61. end
  62.  
  63. -- Update FOV Circle Position to be centered around the mouse
  64. local function updateFOVCircle()
  65. local mousePosition = UserInputService:GetMouseLocation()
  66. FOVCircle.Position = mousePosition -- Centers the FOV circle at the current mouse position
  67. end
  68.  
  69. -- Camlock functionality
  70. local function camlockAtTarget(target)
  71. if target and target.Character and target.Character:FindFirstChild("Head") then
  72. -- Lock the camera's CFrame onto the target's head
  73. Camera.CFrame = CFrame.new(Camera.CFrame.Position, target.Character.Head.Position)
  74. end
  75. end
  76.  
  77. -- Silent Aim functionality
  78. local function silentAimAtTarget(target)
  79. if target and target.Character and target.Character:FindFirstChild("Head") then
  80. -- Silently aim at the target by adjusting the camera's direction
  81. Camera.CFrame = CFrame.new(Camera.CFrame.Position, target.Character.Head.Position)
  82. end
  83. end
  84.  
  85. -- Main loop to handle aiming
  86. RunService.RenderStepped:Connect(function()
  87. updateFOVCircle()
  88.  
  89. local target = getNearestPlayer()
  90.  
  91. if target then
  92. if isThirdPerson() then
  93. camlockAtTarget(target) -- Use camlock in third-person
  94. else
  95. silentAimAtTarget(target) -- Use silent aim in first-person
  96. end
  97. end
  98. end)
  99.  
  100. -- Cleanup on game exit
  101. game.Players.LocalPlayer.OnTeleport:Connect(function()
  102. FOVCircle:Remove()
  103. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement