Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local localPlayer = game:GetService("Players").LocalPlayer
- local currentCamera = game:GetService("Workspace").CurrentCamera
- local mouse = localPlayer:GetMouse()
- function getClosestPlayerToCursor()
- local closestPlayer = nil
- local shortestDistance = math.huge
- for i, v in pairs(game:GetService("Players"):GetPlayers()) do
- 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
- local pos = currentCamera:WorldToViewportPoint(v.Character.Head.Position)
- local magnitude = (Vector2.new(pos.X, pos.Y) - Vector2.new(mouse.X, mouse.Y)).magnitude
- if magnitude < shortestDistance then
- closestPlayer = v
- shortestDistance = magnitude
- end
- end
- end
- return closestPlayer
- end
- hookfunction(workspace.FindPartOnRayWithIgnoreList, function(...)
- if getClosestPlayerToCursor() then
- local closest = getClosestPlayerToCursor().Character.Head
- return closest, closest.Position, Vector3.new(0, 0, 0), closest.Material
- end
- end)
Add Comment
Please, Sign In to add comment