Advertisement
Guest User

KAT Script

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