Advertisement
CriShoux

Untitled

Oct 12th, 2019
956
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. local localPlayer = game:GetService("Players").LocalPlayer
  2. local currentCamera = game:GetService("Workspace").CurrentCamera
  3. local mouse = localPlayer:GetMouse()
  4.  
  5. local function getClosestPlayerToCursor()
  6. local closestPlayer = nil
  7. local shortestDistance = math.huge
  8.  
  9. for i, v in pairs(game:GetService("Players"):GetPlayers()) do
  10. if v.Name ~= localPlayer.Name then
  11. if v.Character and v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health ~= 0 and v.Character:FindFirstChild("HumanoidRootPart") and v.Character:FindFirstChild("Head") then
  12. local pos = currentCamera:WorldToViewportPoint(v.Character.HumanoidRootPart.Position)
  13. local magnitude = (Vector2.new(pos.X, pos.Y) - Vector2.new(mouse.X, mouse.Y)).magnitude
  14.  
  15. if magnitude < shortestDistance then
  16. closestPlayer = v
  17. shortestDistance = magnitude
  18. end
  19. end
  20. end
  21. end
  22.  
  23. return closestPlayer or localPlayer
  24. end
  25.  
  26. local mt = getrawmetatable(game)
  27. local oldNamecall = mt.__namecall
  28. if setreadonly then setreadonly(mt, false) else make_writeable(mt, true) end
  29. local namecallMethod = getnamecallmethod or get_namecall_method
  30. local newClose = newcclosure or function(f) return f end
  31.  
  32. mt.__namecall = newClose(function(...)
  33. local method = namecallMethod()
  34. local args = {...}
  35.  
  36. if tostring(method) == "FireServer" and tostring(args[1]) == "Shoot" then
  37. args[2] = getClosestPlayerToCursor().Character.Head.Position
  38. args[4][1][2] = getClosestPlayerToCursor().Character.Head
  39. args[4][1][1] = getClosestPlayerToCursor().Character.Head.Position
  40. args[4][1][3] = getClosestPlayerToCursor().Character.Head.Position
  41. args[4][1][6] = getClosestPlayerToCursor().Character.Head.Position
  42. end
  43.  
  44. return oldNamecall(...)
  45. end)
  46.  
  47. if setreadonly then setreadonly(mt, true) else make_writeable(mt, false) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement