Advertisement
AndrewRedd730

Untitled

Feb 10th, 2021
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. local Camera = game:GetService("Workspace").CurrentCamera
  2. local Players = game:GetService("Players")
  3. local LocalPlayer = game:GetService("Players").LocalPlayer
  4.  
  5. local function GetClosestPlayer()
  6. local ClosestPlayer = nil
  7. local FarthestDistance = math.huge
  8.  
  9. for i, v in pairs(Players.GetPlayers(Players)) do
  10. if v ~= LocalPlayer and v.Character and v.Character.FindFirstChild(v.Character, "HumanoidRootPart") then
  11. local DistanceFromPlayer = (LocalPlayer.Character.HumanoidRootPart.Position - v.Character.HumanoidRootPart.Position).Magnitude
  12.  
  13. if DistanceFromPlayer < FarthestDistance then
  14. FarthestDistance = DistanceFromPlayer
  15. ClosestPlayer = v
  16. end
  17. end
  18. end
  19.  
  20. if ClosestPlayer then
  21. return ClosestPlayer
  22. end
  23. end
  24.  
  25. local GameMetaTable = getrawmetatable(game)
  26. local OldGameMetaTableNamecall = GameMetaTable.__namecall
  27. setreadonly(GameMetaTable, false)
  28.  
  29. GameMetaTable.__namecall = newcclosure(function(object, ...)
  30. local NamecallMethod = getnamecallmethod()
  31. local Arguments = {...}
  32.  
  33. if tostring(NamecallMethod) == "FindPartOnRayWithIgnoreList" then
  34. local ClosestPlayer = GetClosestPlayer()
  35.  
  36. if ClosestPlayer and ClosestPlayer.Character then
  37. Arguments[1] = Ray.new(Camera.CFrame.Position, (ClosestPlayer.Character.Head.Position - Camera.CFrame.Position).Unit * (Camera.CFrame.Position - ClosestPlayer.Character.Head.Position).Magnitude)
  38. end
  39. end
  40.  
  41. return OldGameMetaTableNamecall(object, unpack(Arguments))
  42. end)
  43.  
  44. setreadonly(GameMetaTable, true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement