Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Optimized ESP System
- - Fixed lag issues
- - Tracers from center of screen
- - Clear player names and health display
- ]]
- -- Services
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- -- Core instances
- local LocalPlayer = Players.LocalPlayer
- local Camera = workspace.CurrentCamera
- -- Storage tables
- local ESP = {}
- local Tracers = {}
- local NameTags = {}
- local HealthBars = {}
- -- Settings
- local REFRESH_RATE = 1 -- Update every frame (set higher like 2-3 if still laggy)
- local MAX_DISTANCE = 1000 -- Max distance to render ESP
- local NAME_OFFSET = Vector3.new(0, 2, 0) -- Offset for name tags
- -- Clean up function to improve performance
- local function cleanUpForPlayer(player)
- if ESP[player] then ESP[player]:Remove(); ESP[player] = nil end
- if Tracers[player] then Tracers[player]:Remove(); Tracers[player] = nil end
- if NameTags[player] then
- if NameTags[player].Box then NameTags[player].Box:Remove() end
- if NameTags[player].Text then NameTags[player].Text:Remove() end
- NameTags[player] = nil
- end
- if HealthBars[player] then
- if HealthBars[player].Background then HealthBars[player].Background:Remove() end
- if HealthBars[player].Fill then HealthBars[player].Fill:Remove() end
- HealthBars[player] = nil
- end
- end
- -- Performance improvement: pre-compute screen center
- local screenCenter = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
- -- Update screen center when viewport changes
- Camera:GetPropertyChangedSignal("ViewportSize"):Connect(function()
- screenCenter = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2)
- end)
- -- Calculate distance for optimization
- local function getDistance(position)
- if not LocalPlayer.Character or not LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then
- return 1000
- end
- return (LocalPlayer.Character.HumanoidRootPart.Position - position).Magnitude
- end
- -- Counter for refresh rate
- local frameCounter = 0
- -- Player left cleanup
- Players.PlayerRemoving:Connect(cleanUpForPlayer)
- -- Main ESP loop with optimizations
- RunService.RenderStepped:Connect(function()
- -- Performance throttling
- frameCounter = frameCounter + 1
- if frameCounter < REFRESH_RATE then return end
- frameCounter = 0
- -- Check if local player has a character
- if not LocalPlayer.Character or not LocalPlayer.Character:FindFirstChild("HumanoidRootPart") then
- return
- end
- -- Process each player
- for _, player in pairs(Players:GetPlayers()) do
- if player ~= LocalPlayer then
- local character = player.Character
- local hrp = character and character:FindFirstChild("HumanoidRootPart")
- local humanoid = character and character:FindFirstChild("Humanoid")
- local head = character and character:FindFirstChild("Head")
- -- Check for valid character and humanoid
- if not hrp or not humanoid or humanoid.Health <= 0 then
- cleanUpForPlayer(player)
- continue
- end
- -- Performance optimization: Skip distant players
- local distance = getDistance(hrp.Position)
- if distance > MAX_DISTANCE then
- -- Hide elements if player is too far
- if ESP[player] then ESP[player].Visible = false end
- if Tracers[player] then Tracers[player].Visible = false end
- if NameTags[player] and NameTags[player].Text then NameTags[player].Text.Visible = false end
- if NameTags[player] and NameTags[player].Box then NameTags[player].Box.Visible = false end
- if HealthBars[player] then
- if HealthBars[player].Background then HealthBars[player].Background.Visible = false end
- if HealthBars[player].Fill then HealthBars[player].Fill.Visible = false end
- end
- continue
- end
- -- Check if player is on screen
- local pos, onScreen = Camera:WorldToViewportPoint(hrp.Position)
- if onScreen then
- -- Set color based on health (gradient from green to red)
- local healthPercent = humanoid.Health / humanoid.MaxHealth
- local playerColor = Color3.new(1 - healthPercent, healthPercent, 0)
- -- ESP Box
- if not ESP[player] then
- local box = Drawing.new("Square")
- box.Thickness = 2
- box.Color = playerColor
- box.Filled = false
- box.Transparency = 1
- ESP[player] = box
- end
- -- Set ESP box size based on distance
- local size = 6 * (1000 / distance)
- size = math.min(size, 20) -- Cap maximum size
- ESP[player].Size = Vector2.new(size * 1.5, size * 3)
- ESP[player].Position = Vector2.new(pos.X - (size * 1.5) / 2, pos.Y - (size * 3) / 2)
- ESP[player].Color = playerColor
- ESP[player].Visible = true
- -- Tracer (from center of screen)
- if not Tracers[player] then
- local line = Drawing.new("Line")
- line.Thickness = 1
- line.Color = playerColor
- line.Transparency = 1
- Tracers[player] = line
- end
- -- Always start from center of screen as requested
- Tracers[player].From = screenCenter
- Tracers[player].To = Vector2.new(pos.X, pos.Y)
- Tracers[player].Color = Color3.new(1, 0, 0) -- Red
- Tracers[player].Visible = true
- -- Name tag with health
- if head then
- local headPos, headOnScreen = Camera:WorldToViewportPoint(head.Position + NAME_OFFSET)
- if headOnScreen then
- -- Create name tag and health display if it doesn't exist
- if not NameTags[player] then
- -- Black background box
- local nameBox = Drawing.new("Square")
- nameBox.Thickness = 1
- nameBox.Color = Color3.new(0, 0, 0)
- nameBox.Transparency = 0.7
- nameBox.Filled = true
- -- Text for name and health
- local nameText = Drawing.new("Text")
- nameText.Size = 16
- nameText.Center = true
- nameText.Outline = true
- nameText.Color = Color3.new(1, 1, 1)
- nameText.OutlineColor = Color3.new(0, 0, 0)
- NameTags[player] = {
- Box = nameBox,
- Text = nameText
- }
- end
- -- Update the text to show name and health
- local healthText = math.floor(humanoid.Health) .. "/" .. math.floor(humanoid.MaxHealth)
- NameTags[player].Text.Text = player.Name .. " [" .. healthText .. "]"
- -- Get text bounds for proper box sizing
- local textBounds = NameTags[player].Text.TextBounds
- -- Position the box and text
- NameTags[player].Box.Size = Vector2.new(textBounds.X + 10, textBounds.Y + 5)
- NameTags[player].Box.Position = Vector2.new(headPos.X - (textBounds.X / 2) - 5, headPos.Y - (textBounds.Y / 2) - 2)
- NameTags[player].Text.Position = Vector2.new(headPos.X, headPos.Y)
- -- Make both visible
- NameTags[player].Box.Visible = true
- NameTags[player].Text.Visible = true
- -- Health bar
- if not HealthBars[player] then
- -- Background (black)
- local background = Drawing.new("Square")
- background.Thickness = 1
- background.Color = Color3.new(0, 0, 0)
- background.Transparency = 0.7
- background.Filled = true
- -- Fill (colored based on health)
- local fill = Drawing.new("Square")
- fill.Thickness = 1
- fill.Transparency = 1
- fill.Filled = true
- HealthBars[player] = {
- Background = background,
- Fill = fill
- }
- end
- -- Set health bar positions
- local barWidth = 50 * (1000 / math.max(distance, 100))
- barWidth = math.min(barWidth, 100) -- Cap maximum width
- local barHeight = 5 * (1000 / math.max(distance, 100))
- barHeight = math.min(barHeight, 10) -- Cap maximum height
- -- Position health bar above name tag
- local barY = headPos.Y - textBounds.Y - barHeight - 5
- HealthBars[player].Background.Size = Vector2.new(barWidth, barHeight)
- HealthBars[player].Background.Position = Vector2.new(headPos.X - barWidth/2, barY)
- -- Set health fill width based on health percentage
- local fillWidth = barWidth * healthPercent
- HealthBars[player].Fill.Size = Vector2.new(fillWidth, barHeight)
- HealthBars[player].Fill.Position = Vector2.new(headPos.X - barWidth/2, barY)
- HealthBars[player].Fill.Color = playerColor
- HealthBars[player].Background.Visible = true
- HealthBars[player].Fill.Visible = true
- else
- -- Hide name and health if head not on screen
- if NameTags[player] then
- NameTags[player].Box.Visible = false
- NameTags[player].Text.Visible = false
- end
- if HealthBars[player] then
- HealthBars[player].Background.Visible = false
- HealthBars[player].Fill.Visible = false
- end
- end
- end
- else
- -- Hide everything if not on screen
- if ESP[player] then ESP[player].Visible = false end
- if Tracers[player] then Tracers[player].Visible = false end
- if NameTags[player] then
- NameTags[player].Box.Visible = false
- NameTags[player].Text.Visible = false
- end
- if HealthBars[player] then
- HealthBars[player].Background.Visible = false
- HealthBars[player].Fill.Visible = false
- end
- end
- end
- end
- end)
- -- Show startup notification
- local function showNotification()
- game.StarterGui:SetCore("SendNotification", {
- Title = "ESP Loaded",
- Text = "Optimized ESP with center tracers and health display",
- Duration = 3
- })
- end
- showNotification()
- print("Optimized ESP loaded successfully!")
Advertisement
Add Comment
Please, Sign In to add comment