Advertisement
yaminameis59

Silent Aim

Apr 15th, 2023
711
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.78 KB | Gaming | 0 0
  1. -- VARIABLES
  2. local plrs = game:GetService("Players")
  3. local plr = plrs.LocalPlayer
  4. local mouse = plr:GetMouse()
  5. local camera = game:GetService("Workspace").CurrentCamera
  6.  
  7. -- FUNCTIONS
  8. function notBehindWall(target)
  9.     local ray = Ray.new(plr.Character.Head.Position, (target.Position - plr.Character.Head.Position).Unit * 300)
  10.     local part, position = game:GetService("Workspace"):FindPartOnRayWithIgnoreList(ray, {plr.Character}, false, true)
  11.     if part then
  12.         local humanoid = part.Parent:FindFirstChildOfClass("Humanoid")
  13.         if not humanoid then
  14.             humanoid = part.Parent.Parent == target.Parent
  15.         end
  16.         if humanoid and target and humanoid.Parent == target.Parent then
  17.             local pos, visible = camera:WorldToScreenPoint(target.Position)
  18.             if visible then
  19.                 return true
  20.             end
  21.         end
  22.     end
  23. end
  24.  
  25. function getPlayerClosestToMouse()
  26.     local target = nil
  27.     local maxDist = 100
  28.     for _,v in pairs(plrs:GetPlayers()) do
  29.         if v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health ~= 0 and v.Character:FindFirstChild("HumanoidRootPart") and v.TeamColor ~= plr.TeamColor then
  30.             local pos, vis = camera:WorldToViewportPoint(v.Character.HumanoidRootPart.Position)
  31.             local dist = (Vector2.new(mouse.X, mouse.Y) - Vector2.new(pos.X, pos.Y)).magnitude
  32.             if dist < maxDist and vis then
  33.                 local torsoPos = camera:WorldToViewportPoint(v.Character.HumanoidRootPart.Position)
  34.                 local torsoDist = (Vector2.new(mouse.X, mouse.Y) - Vector2.new(torsoPos.X, torsoPos.Y)).magnitude
  35.                 local headPos = camera:WorldToViewportPoint(v.Character.Head.Position)
  36.                 local headDist = (Vector2.new(mouse.X, mouse.Y) - Vector2.new(headPos.X, headPos.Y)).magnitude
  37.                 if torsoDist > headDist then
  38.                     if notBehindWall(v.Character.Head) then
  39.                         target = v.Character.Head
  40.                     end
  41.                 else
  42.                     if notBehindWall(v.Character.HumanoidRootPart) then
  43.                         target = v.Character.HumanoidRootPart
  44.                     end
  45.                 end
  46.                 maxDist = dist
  47.             end
  48.         end
  49.     end
  50. end
  51.  
  52. -- HOOKING TO THE REMOTE
  53. local gmt = getrawmetatable(game)
  54. setreadonly(gmt, false)
  55. local oldNamecall = gmt.__namecall
  56.  
  57. gmt.__namecall = newcclosure(function(self, ...)
  58.     local Args = {...}
  59.     local method = getnamecallmethod()
  60.     if tostring(self) == "HitPart" and tostring(method) == "FireServer" then
  61.         Args[1] = getPlayerClosestToMouse()
  62.         Args[2] = getPlayerClosestToMouse().Position
  63.         return self.FireServer(self, unpack(Args))
  64.     end
  65.     return oldNamecall(self, ...)
  66. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement