Examples
Box ESP with teams and distance
A box, the display name and the distance over every other player. Teammates get a blue box and everyone else a red one. Players further away than MAX_DISTANCE are left out.
It builds each player's drawings the first time it sees them and removes them when the player leaves. Everything else happens in one RenderStepped handler.
Luau
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local MAX_DISTANCE = 1000
local ENEMY = Color3.fromRGB(255, 70, 70)
local TEAM = Color3.fromRGB(80, 160, 255)
local esp = {}
local function newText()
local text = Drawing.new("Text")
text.FontSize = 13
text.Center = true
text.Outline = true
text.Color = Color3.new(1, 1, 1)
return text
end
local function drawingsFor(player)
local d = esp[player]
if not d then
local box = Drawing.new("Square")
box.Thickness = 1.5
d = { box = box, name = newText(), distance = newText() }
esp[player] = d
end
return d
end
local function show(d, visible)
d.box.Visible = visible
d.name.Visible = visible
d.distance.Visible = visible
end
RunService.RenderStepped:Connect(function()
local camera = workspace.CurrentCamera
local present = {}
for _, player in ipairs(Players:GetPlayers()) do
if player ~= LocalPlayer then
present[player] = true
local d = drawingsFor(player)
local character = player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
local root = character and character:FindFirstChild("HumanoidRootPart")
local visible = false
if root and humanoid and humanoid.Health > 0 then
local distance = (root.Position - camera.Position).Magnitude
local top, topOn = WorldToScreen(root.Position + Vector3.new(0, 3, 0))
local bottom, bottomOn = WorldToScreen(root.Position - Vector3.new(0, 3.5, 0))
if distance <= MAX_DISTANCE and topOn and bottomOn then
local height = bottom.Y - top.Y
local width = height * 0.6
local teammate = player.Team ~= nil and player.Team == LocalPlayer.Team
d.box.Color = teammate and TEAM or ENEMY
d.box.Position = Vector2.new(top.X - width / 2, top.Y)
d.box.Size = Vector2.new(width, height)
d.name.Text = player.DisplayName
d.name.Position = Vector2.new(top.X, top.Y - 16)
d.distance.Text = string.format("%d studs", math.floor(distance))
d.distance.Position = Vector2.new(top.X, bottom.Y + 2)
visible = true
end
end
show(d, visible)
end
end
-- players who left: remove their drawings
for player, d in pairs(esp) do
if not present[player] then
d.box:Remove()
d.name:Remove()
d.distance:Remove()
esp[player] = nil
end
end
end)Things to change
MAX_DISTANCEin studs. Set it tomath.hugeto show everyone.- The box shape:
0.6is the width as a share of the height. For a box that fits each character exactly, usecharacter:GetExtentsSize(). - To hide teammates instead of colouring them, call
show(d, false)whenteammateis true.