Alex_Scripter13

sil

Nov 10th, 2024
2,452
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. local replicated_storage = game.GetService(game, "ReplicatedStorage");
  2. local players = game.GetService(game, "Players");
  3.  
  4. local camera = workspace.CurrentCamera;
  5. local utility = require(replicated_storage.Modules.Utility);
  6.  
  7. local get_players = function() -- this is dumb asf, feel free to modify.
  8. local entities = {};
  9.  
  10. for _, child in workspace.GetChildren(workspace) do
  11. if child.FindFirstChildOfClass(child, "Humanoid") then
  12. table.insert(entities, child);
  13. elseif child.Name == "HurtEffect" then
  14. for _, hurt_player in child.GetChildren(child) do
  15. if (hurt_player.ClassName ~= "Highlight") then
  16. table.insert(entities, hurt_player);
  17. end
  18. end
  19. end
  20. end
  21. return entities
  22. end
  23. local get_closest_player = function()
  24. local closest, closest_distance = nil, math.huge;
  25. local character = players.LocalPlayer.Character;
  26.  
  27. if (character == nil) then
  28. return;
  29. end
  30.  
  31. for _, player in get_players() do
  32. if (player == players.LocalPlayer) then
  33. continue;
  34. end
  35.  
  36. if (not player:FindFirstChild("HumanoidRootPart")) then
  37. continue;
  38. end
  39.  
  40. local position, on_screen = camera.WorldToViewportPoint(camera, player.HumanoidRootPart.Position);
  41.  
  42. if (on_screen == false) then
  43. continue;
  44. end
  45.  
  46. local center = Vector2.new(camera.ViewportSize.X / 2, camera.ViewportSize.Y / 2);
  47. local distance = (center - Vector2.new(position.X, position.Y)).Magnitude;
  48.  
  49. if (distance > closest_distance) then
  50. continue;
  51. end
  52.  
  53. closest = player;
  54. closest_distance = distance;
  55. end
  56. return closest;
  57. end
  58.  
  59. local old = utility.Raycast; utility.Raycast = function(...)
  60. local arguments = {...};
  61.  
  62. if (#arguments > 0 and arguments[4] == 999) then
  63. local closest = get_closest_player();
  64.  
  65. if (closest) then
  66. arguments[3] = closest.Head.Position;
  67. end
  68. end
  69. return old(table.unpack(arguments));
  70. end
Add Comment
Please, Sign In to add comment