Advertisement
A_Xcom

Roblox Box, Health ESP

Mar 2nd, 2025
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.65 KB | Source Code | 0 0
  1. -- Player ESP Script with Team Colors and Health Bars
  2. -- Place this script in a LocalScript inside StarterPlayerScripts
  3.  
  4. local Players = game:GetService("Players")
  5. local RunService = game:GetService("RunService")
  6. local LocalPlayer = Players.LocalPlayer
  7. local Camera = workspace.CurrentCamera
  8.  
  9. -- ESP Configuration
  10. local ESP = {
  11.     Enabled = true,
  12.     ShowTeamColor = true,
  13.     ShowHealthBar = true,
  14.     TextSize = 14,
  15.     BoxThickness = 2,
  16.     BoxTransparency = 0.5,
  17.     TextTransparency = 0,
  18.     HealthBarThickness = 2,
  19.     HealthBarWidth = 50,
  20.     HealthBarHeight = 5,
  21.     MaxDistance = 5000, -- Increased max distance to 5000 studs
  22. }
  23.  
  24. -- Storage for ESP drawings
  25. local ESPObjects = {}
  26.  
  27. -- Function to create ESP objects for a player
  28. local function CreateESPForPlayer(player)
  29.     if player == LocalPlayer then return end
  30.    
  31.     local espObject = {}
  32.    
  33.     -- Box outline for player
  34.     espObject.Box = Drawing.new("Square")
  35.     espObject.Box.Visible = false
  36.     espObject.Box.Thickness = ESP.BoxThickness
  37.     espObject.Box.Transparency = ESP.BoxTransparency
  38.     espObject.Box.Filled = false
  39.    
  40.     -- Player name and health text
  41.     espObject.Text = Drawing.new("Text")
  42.     espObject.Text.Visible = false
  43.     espObject.Text.Size = ESP.TextSize
  44.     espObject.Text.Center = true
  45.     espObject.Text.Outline = true
  46.     espObject.Text.Transparency = ESP.TextTransparency
  47.    
  48.     -- Health bar background (gray)
  49.     espObject.HealthBG = Drawing.new("Square")
  50.     espObject.HealthBG.Visible = false
  51.     espObject.HealthBG.Thickness = ESP.HealthBarThickness
  52.     espObject.HealthBG.Filled = true
  53.     espObject.HealthBG.Color = Color3.fromRGB(100, 100, 100)
  54.     espObject.HealthBG.Transparency = 0.7
  55.    
  56.     -- Health bar fill (green to red depending on health)
  57.     espObject.HealthBar = Drawing.new("Square")
  58.     espObject.HealthBar.Visible = false
  59.     espObject.HealthBar.Thickness = ESP.HealthBarThickness
  60.     espObject.HealthBar.Filled = true
  61.     espObject.HealthBar.Transparency = 0.7
  62.    
  63.     ESPObjects[player] = espObject
  64.    
  65.     -- Clear ESP when player leaves
  66.     player.AncestryChanged:Connect(function()
  67.         if not player:IsDescendantOf(game) then
  68.             if ESPObjects[player] then
  69.                 for _, object in pairs(ESPObjects[player]) do
  70.                     object:Remove()
  71.                 end
  72.                 ESPObjects[player] = nil
  73.             end
  74.         end
  75.     end)
  76. end
  77.  
  78. -- Create ESP for all existing players
  79. for _, player in pairs(Players:GetPlayers()) do
  80.     if player ~= LocalPlayer then
  81.         CreateESPForPlayer(player)
  82.     end
  83. end
  84.  
  85. -- Create ESP for new players who join
  86. Players.PlayerAdded:Connect(CreateESPForPlayer)
  87.  
  88. -- Clear ESP for players who leave
  89. Players.PlayerRemoving:Connect(function(player)
  90.     if ESPObjects[player] then
  91.         for _, object in pairs(ESPObjects[player]) do
  92.             object:Remove()
  93.         end
  94.         ESPObjects[player] = nil
  95.     end
  96. end)
  97.  
  98. -- Function to get player team color
  99. local function GetPlayerTeamColor(player)
  100.     if player.Team then
  101.         return player.TeamColor.Color
  102.     end
  103.     return Color3.fromRGB(255, 255, 255) -- White for no team
  104. end
  105.  
  106. -- Function to get health color based on percentage
  107. local function GetHealthColor(health, maxHealth)
  108.     local healthPercent = health / maxHealth
  109.    
  110.     -- Gradient from red to green based on health percentage
  111.     local r = math.clamp(2 * (1 - healthPercent), 0, 1)
  112.     local g = math.clamp(2 * healthPercent, 0, 1)
  113.    
  114.     return Color3.new(r, g, 0)
  115. end
  116.  
  117. -- Update ESP on each frame
  118. RunService.RenderStepped:Connect(function()
  119.     if not ESP.Enabled then
  120.         -- Hide all ESP elements if disabled
  121.         for _, espObject in pairs(ESPObjects) do
  122.             for _, drawing in pairs(espObject) do
  123.                 drawing.Visible = false
  124.             end
  125.         end
  126.         return
  127.     end
  128.    
  129.     for player, espObject in pairs(ESPObjects) do
  130.         -- Get character and make sure it's valid
  131.         local character = player.Character
  132.         if not character or not character:FindFirstChild("HumanoidRootPart") or not character:FindFirstChild("Humanoid") then
  133.             for _, drawing in pairs(espObject) do
  134.                 drawing.Visible = false
  135.             end
  136.             continue
  137.         end
  138.        
  139.         local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  140.         local humanoid = character:FindFirstChild("Humanoid")
  141.        
  142.         -- Get health information
  143.         local health = humanoid.Health
  144.         local maxHealth = humanoid.MaxHealth
  145.        
  146.         -- Check if character is on screen and within max distance
  147.         local vector, onScreen = Camera:WorldToViewportPoint(humanoidRootPart.Position)
  148.         local distance = (humanoidRootPart.Position - Camera.CFrame.Position).Magnitude
  149.        
  150.         -- Only show ESP if player is on screen and within max distance
  151.         if onScreen and distance <= ESP.MaxDistance then
  152.             -- Get player size for box ESP (using character bounds)
  153.             local topPosition = humanoidRootPart.Position + Vector3.new(0, 3, 0)
  154.             local bottomPosition = humanoidRootPart.Position - Vector3.new(0, 3, 0)
  155.            
  156.             local topVector = Camera:WorldToViewportPoint(topPosition)
  157.             local bottomVector = Camera:WorldToViewportPoint(bottomPosition)
  158.            
  159.             local height = math.abs(topVector.Y - bottomVector.Y)
  160.             local width = height * 0.6
  161.            
  162.             local boxPosition = Vector2.new(vector.X - width / 2, vector.Y - height / 2)
  163.             local boxSize = Vector2.new(width, height)
  164.            
  165.             -- Update box
  166.             espObject.Box.Position = boxPosition
  167.             espObject.Box.Size = boxSize
  168.             espObject.Box.Color = GetPlayerTeamColor(player)
  169.             espObject.Box.Visible = true
  170.            
  171.             -- Update player name and health text
  172.             espObject.Text.Position = Vector2.new(vector.X, boxPosition.Y - 20)
  173.             espObject.Text.Text = string.format("%s [%.0f%%]", player.Name, (health / maxHealth) * 100)
  174.             espObject.Text.Color = GetPlayerTeamColor(player)
  175.             espObject.Text.Visible = true
  176.            
  177.             -- Update health bar background
  178.             espObject.HealthBG.Position = Vector2.new(vector.X - ESP.HealthBarWidth / 2, boxPosition.Y - 10)
  179.             espObject.HealthBG.Size = Vector2.new(ESP.HealthBarWidth, ESP.HealthBarHeight)
  180.             espObject.HealthBG.Visible = ESP.ShowHealthBar
  181.            
  182.             -- Update health bar fill
  183.             local healthPercent = health / maxHealth
  184.             espObject.HealthBar.Position = Vector2.new(vector.X - ESP.HealthBarWidth / 2, boxPosition.Y - 10)
  185.             espObject.HealthBar.Size = Vector2.new(ESP.HealthBarWidth * healthPercent, ESP.HealthBarHeight)
  186.             espObject.HealthBar.Color = GetHealthColor(health, maxHealth)
  187.             espObject.HealthBar.Visible = ESP.ShowHealthBar
  188.         else
  189.             -- Hide ESP elements if player is off screen or too far
  190.             for _, drawing in pairs(espObject) do
  191.                 drawing.Visible = false
  192.             end
  193.         end
  194.     end
  195. end)
  196.  
  197. -- Add toggle functionality (can be bound to a key)
  198. local UserInputService = game:GetService("UserInputService")
  199.  
  200. UserInputService.InputBegan:Connect(function(input)
  201.     if input.KeyCode == Enum.KeyCode.RightAlt then
  202.         ESP.Enabled = not ESP.Enabled
  203.     end
  204. end)
  205.  
  206. -- Instructions on how to use this script
  207. print("ESP Script loaded! Press Right Alt to toggle ESP.")
  208. print("ESP shows player boxes by team color and health bars.")
  209. print("Maximum ESP rendering distance: 5000 studs")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement