Advertisement
CriShoux

Untitled

Nov 4th, 2019
3,733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 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. 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 ~= localPlayer and v.Character and v.Character:FindFirstChildOfClass("Humanoid") and v.Character:FindFirstChildOfClass("Humanoid").Health ~= 0 and v.Character:FindFirstChild("Head") and v.TeamColor ~= game:GetService("Players").LocalPlayer.TeamColor then
  11. local pos = currentCamera:WorldToViewportPoint(v.Character.Head.Position)
  12. local magnitude = (Vector2.new(pos.X, pos.Y) - Vector2.new(mouse.X, mouse.Y)).magnitude
  13.  
  14. if magnitude < shortestDistance then
  15. closestPlayer = v
  16. shortestDistance = magnitude
  17. end
  18. end
  19. end
  20.  
  21. return closestPlayer
  22. end
  23.  
  24. hookfunction(workspace.FindPartOnRayWithIgnoreList, function(...)
  25. if getClosestPlayerToCursor() then
  26. local closest = getClosestPlayerToCursor().Character.Head
  27. return closest, closest.Position, Vector3.new(0, 0, 0), closest.Material
  28. end
  29. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement