YESSIR455bb

ESP

May 11th, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.31 KB | None | 0 0
  1. --[[
  2. Optimized ESP System
  3. - Fixed lag issues
  4. - Tracers from center of screen
  5. - Clear player names and health display
  6. ]]
  7.  
  8. -- Services
  9. local Players = game:GetService("Players")
  10. local RunService = game:GetService("RunService")
  11.  
  12. -- Core instances
  13. local LocalPlayer = Players.LocalPlayer
  14. local Camera = workspace.CurrentCamera
  15.  
  16. -- Storage tables
  17. local ESP = {}
  18. local Tracers = {}
  19. local NameTags = {}
  20. local HealthBars = {}
  21.  
  22. -- Settings
  23. local REFRESH_RATE = 1 -- Update every frame (set higher like 2-3 if still laggy)
  24. local MAX_DISTANCE = 1000 -- Max distance to render ESP
  25. local NAME_OFFSET = Vector3.new(0, 2, 0) -- Offset for name tags
  26.  
  27. -- Clean up function to improve performance
  28. local function cleanUpForPlayer(player)
  29. if ESP[player] then ESP[player]:Remove(); ESP[player] = nil end
  30. if Tracers[player] then Tracers[player]:Remove(); Tracers[player] = nil end
  31.  
  32. if NameTags[player] then
  33. if NameTags[player].Box then NameTags[player].Box:Remove() end
  34. if NameTags[player].Text then NameTags[player].Text:Remove() end
  35. NameTags[player] = nil
  36. end
  37.  
  38. if HealthBars[player] then
  39. if HealthBars[player].Background then HealthBars[player].Background:Remove() end
  40. if HealthBars[player].Fill then HealthBars[player].Fill:Remove() end
  41. HealthBars[player] = nil
  42. end
  43. end
  44.  
  45. -- Performance improvement: pre-compute screen center
  46. local screenCenter = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
  47.  
  48. -- Update screen center when viewport changes
  49. Camera:GetPropertyChangedSignal("ViewportSize"):Connect(function()
  50. screenCenter = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
  51. end)
  52.  
  53. -- Calculate distance for optimization
  54. local function getDistance(position)
  55. if not LocalPlayer.Character or not LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then
  56. return 1000
  57. end
  58. return (LocalPlayer.Character.HumanoidRootPart.Position - position).Magnitude
  59. end
  60.  
  61. -- Counter for refresh rate
  62. local frameCounter = 0
  63.  
  64. -- Player left cleanup
  65. Players.PlayerRemoving:Connect(cleanUpForPlayer)
  66.  
  67. -- Main ESP loop with optimizations
  68. RunService.RenderStepped:Connect(function()
  69. -- Performance throttling
  70. frameCounter = frameCounter + 1
  71. if frameCounter < REFRESH_RATE then return end
  72. frameCounter = 0
  73.  
  74. -- Check if local player has a character
  75. if not LocalPlayer.Character or not LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then
  76. return
  77. end
  78.  
  79. -- Process each player
  80. for _, player in pairs(Players:GetPlayers()) do
  81. if player ~= LocalPlayer then
  82. local character = player.Character
  83. local hrp = character and character:FindFirstChild("HumanoidRootPart")
  84. local humanoid = character and character:FindFirstChild("Humanoid")
  85. local head = character and character:FindFirstChild("Head")
  86.  
  87. -- Check for valid character and humanoid
  88. if not hrp or not humanoid or humanoid.Health <= 0 then
  89. cleanUpForPlayer(player)
  90. continue
  91. end
  92.  
  93. -- Performance optimization: Skip distant players
  94. local distance = getDistance(hrp.Position)
  95. if distance > MAX_DISTANCE then
  96. -- Hide elements if player is too far
  97. if ESP[player] then ESP[player].Visible = false end
  98. if Tracers[player] then Tracers[player].Visible = false end
  99. if NameTags[player] and NameTags[player].Text then NameTags[player].Text.Visible = false end
  100. if NameTags[player] and NameTags[player].Box then NameTags[player].Box.Visible = false end
  101. if HealthBars[player] then
  102. if HealthBars[player].Background then HealthBars[player].Background.Visible = false end
  103. if HealthBars[player].Fill then HealthBars[player].Fill.Visible = false end
  104. end
  105. continue
  106. end
  107.  
  108. -- Check if player is on screen
  109. local pos, onScreen = Camera:WorldToViewportPoint(hrp.Position)
  110.  
  111. if onScreen then
  112. -- Set color based on health (gradient from green to red)
  113. local healthPercent = humanoid.Health / humanoid.MaxHealth
  114. local playerColor = Color3.new(1 - healthPercent, healthPercent, 0)
  115.  
  116. -- ESP Box
  117. if not ESP[player] then
  118. local box = Drawing.new("Square")
  119. box.Thickness = 2
  120. box.Color = playerColor
  121. box.Filled = false
  122. box.Transparency = 1
  123. ESP[player] = box
  124. end
  125.  
  126. -- Set ESP box size based on distance
  127. local size = 6 * (1000 / distance)
  128. size = math.min(size, 20) -- Cap maximum size
  129.  
  130. ESP[player].Size = Vector2.new(size * 1.5, size * 3)
  131. ESP[player].Position = Vector2.new(pos.X - (size * 1.5) / 2, pos.Y - (size * 3) / 2)
  132. ESP[player].Color = playerColor
  133. ESP[player].Visible = true
  134.  
  135. -- Tracer (from center of screen)
  136. if not Tracers[player] then
  137. local line = Drawing.new("Line")
  138. line.Thickness = 1
  139. line.Color = playerColor
  140. line.Transparency = 1
  141. Tracers[player] = line
  142. end
  143.  
  144. -- Always start from center of screen as requested
  145. Tracers[player].From = screenCenter
  146. Tracers[player].To = Vector2.new(pos.X, pos.Y)
  147. Tracers[player].Color = Color3.new(1, 0, 0) -- Red
  148. Tracers[player].Visible = true
  149.  
  150. -- Name tag with health
  151. if head then
  152. local headPos, headOnScreen = Camera:WorldToViewportPoint(head.Position + NAME_OFFSET)
  153.  
  154. if headOnScreen then
  155. -- Create name tag and health display if it doesn't exist
  156. if not NameTags[player] then
  157. -- Black background box
  158. local nameBox = Drawing.new("Square")
  159. nameBox.Thickness = 1
  160. nameBox.Color = Color3.new(0, 0, 0)
  161. nameBox.Transparency = 0.7
  162. nameBox.Filled = true
  163.  
  164. -- Text for name and health
  165. local nameText = Drawing.new("Text")
  166. nameText.Size = 16
  167. nameText.Center = true
  168. nameText.Outline = true
  169. nameText.Color = Color3.new(1, 1, 1)
  170. nameText.OutlineColor = Color3.new(0, 0, 0)
  171.  
  172. NameTags[player] = {
  173. Box = nameBox,
  174. Text = nameText
  175. }
  176. end
  177.  
  178. -- Update the text to show name and health
  179. local healthText = math.floor(humanoid.Health) .. "/" .. math.floor(humanoid.MaxHealth)
  180. NameTags[player].Text.Text = player.Name .. " [" .. healthText .. "]"
  181.  
  182. -- Get text bounds for proper box sizing
  183. local textBounds = NameTags[player].Text.TextBounds
  184.  
  185. -- Position the box and text
  186. NameTags[player].Box.Size = Vector2.new(textBounds.X + 10, textBounds.Y + 5)
  187. NameTags[player].Box.Position = Vector2.new(headPos.X - (textBounds.X / 2) - 5, headPos.Y - (textBounds.Y / 2) - 2)
  188. NameTags[player].Text.Position = Vector2.new(headPos.X, headPos.Y)
  189.  
  190. -- Make both visible
  191. NameTags[player].Box.Visible = true
  192. NameTags[player].Text.Visible = true
  193.  
  194. -- Health bar
  195. if not HealthBars[player] then
  196. -- Background (black)
  197. local background = Drawing.new("Square")
  198. background.Thickness = 1
  199. background.Color = Color3.new(0, 0, 0)
  200. background.Transparency = 0.7
  201. background.Filled = true
  202.  
  203. -- Fill (colored based on health)
  204. local fill = Drawing.new("Square")
  205. fill.Thickness = 1
  206. fill.Transparency = 1
  207. fill.Filled = true
  208.  
  209. HealthBars[player] = {
  210. Background = background,
  211. Fill = fill
  212. }
  213. end
  214.  
  215. -- Set health bar positions
  216. local barWidth = 50 * (1000 / math.max(distance, 100))
  217. barWidth = math.min(barWidth, 100) -- Cap maximum width
  218. local barHeight = 5 * (1000 / math.max(distance, 100))
  219. barHeight = math.min(barHeight, 10) -- Cap maximum height
  220.  
  221. -- Position health bar above name tag
  222. local barY = headPos.Y - textBounds.Y - barHeight - 5
  223.  
  224. HealthBars[player].Background.Size = Vector2.new(barWidth, barHeight)
  225. HealthBars[player].Background.Position = Vector2.new(headPos.X - barWidth/2, barY)
  226.  
  227. -- Set health fill width based on health percentage
  228. local fillWidth = barWidth * healthPercent
  229. HealthBars[player].Fill.Size = Vector2.new(fillWidth, barHeight)
  230. HealthBars[player].Fill.Position = Vector2.new(headPos.X - barWidth/2, barY)
  231. HealthBars[player].Fill.Color = playerColor
  232.  
  233. HealthBars[player].Background.Visible = true
  234. HealthBars[player].Fill.Visible = true
  235. else
  236. -- Hide name and health if head not on screen
  237. if NameTags[player] then
  238. NameTags[player].Box.Visible = false
  239. NameTags[player].Text.Visible = false
  240. end
  241.  
  242. if HealthBars[player] then
  243. HealthBars[player].Background.Visible = false
  244. HealthBars[player].Fill.Visible = false
  245. end
  246. end
  247. end
  248. else
  249. -- Hide everything if not on screen
  250. if ESP[player] then ESP[player].Visible = false end
  251. if Tracers[player] then Tracers[player].Visible = false end
  252.  
  253. if NameTags[player] then
  254. NameTags[player].Box.Visible = false
  255. NameTags[player].Text.Visible = false
  256. end
  257.  
  258. if HealthBars[player] then
  259. HealthBars[player].Background.Visible = false
  260. HealthBars[player].Fill.Visible = false
  261. end
  262. end
  263. end
  264. end
  265. end)
  266.  
  267. -- Show startup notification
  268. local function showNotification()
  269. game.StarterGui:SetCore("SendNotification", {
  270. Title = "ESP Loaded",
  271. Text = "Optimized ESP with center tracers and health display",
  272. Duration = 3
  273. })
  274. end
  275.  
  276. showNotification()
  277. print("Optimized ESP loaded successfully!")
Advertisement
Add Comment
Please, Sign In to add comment