Skibidi242345

Untitled

Dec 20th, 2024
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. -- settings
  2. local settings = {
  3. defaultcolor = Color3.fromRGB(255,0,0),
  4. teamcheck = false,
  5. teamcolor = true
  6. };
  7.  
  8. -- services
  9. local runService = game:GetService("RunService");
  10. local players = game:GetService("Players");
  11.  
  12. -- variables
  13. local localPlayer = players.LocalPlayer;
  14. local camera = workspace.CurrentCamera;
  15.  
  16. -- functions
  17. local newVector2, newColor3, newDrawing = Vector2.new, Color3.new, Drawing.new;
  18. local tan, rad = math.tan, math.rad;
  19. local round = function(...) local a = {}; for i,v in next, table.pack(...) do a[i] = math.round(v); end return unpack(a); end;
  20. local wtvp = function(...) local a, b = camera.WorldToViewportPoint(camera, ...) return newVector2(a.X, a.Y), b, a.Z end;
  21.  
  22. local espCache = {};
  23. local function createEsp(player)
  24. local drawings = {};
  25.  
  26. drawings.box = newDrawing("Square");
  27. drawings.box.Thickness = 1;
  28. drawings.box.Filled = false;
  29. drawings.box.Color = settings.defaultcolor;
  30. drawings.box.Visible = false;
  31. drawings.box.ZIndex = 2;
  32.  
  33. drawings.boxoutline = newDrawing("Square");
  34. drawings.boxoutline.Thickness = 3;
  35. drawings.boxoutline.Filled = false;
  36. drawings.boxoutline.Color = newColor3();
  37. drawings.boxoutline.Visible = false;
  38. drawings.boxoutline.ZIndex = 1;
  39.  
  40. espCache[player] = drawings;
  41. end
  42.  
  43. local function removeEsp(player)
  44. if rawget(espCache, player) then
  45. for _, drawing in next, espCache[player] do
  46. drawing:Remove();
  47. end
  48. espCache[player] = nil;
  49. end
  50. end
  51.  
  52. local function updateEsp(player, esp)
  53. local character = player and player.Character;
  54. if character then
  55. local cframe = character:GetModelCFrame();
  56. local position, visible, depth = wtvp(cframe.Position);
  57. esp.box.Visible = visible;
  58. esp.boxoutline.Visible = visible;
  59.  
  60. if cframe and visible then
  61. local scaleFactor = 1 / (depth * tan(rad(camera.FieldOfView / 2)) * 2) * 1000;
  62. local width, height = round(4 * scaleFactor, 5 * scaleFactor);
  63. local x, y = round(position.X, position.Y);
  64.  
  65. esp.box.Size = newVector2(width, height);
  66. esp.box.Position = newVector2(round(x - width / 2, y - height / 2));
  67. esp.box.Color = settings.teamcolor and player.TeamColor.Color or settings.defaultcolor;
  68.  
  69. esp.boxoutline.Size = esp.box.Size;
  70. esp.boxoutline.Position = esp.box.Position;
  71. end
  72. else
  73. esp.box.Visible = false;
  74. esp.boxoutline.Visible = false;
  75. end
  76. end
  77.  
  78. -- main
  79. for _, player in next, players:GetPlayers() do
  80. if player ~= localPlayer then
  81. createEsp(player);
  82. end
  83. end
  84.  
  85. players.PlayerAdded:Connect(function(player)
  86. createEsp(player);
  87. end);
  88.  
  89. players.PlayerRemoving:Connect(function(player)
  90. removeEsp(player);
  91. end)
  92.  
  93. runService:BindToRenderStep("esp", Enum.RenderPriority.Camera.Value, function()
  94. for player, drawings in next, espCache do
  95. if settings.teamcheck and player.Team == localPlayer.Team then
  96. continue;
  97. end
  98.  
  99. if drawings and player ~= localPlayer then
  100. updateEsp(player, drawings);
  101. end
  102. end
  103. end)
Add Comment
Please, Sign In to add comment