Drawing on screen
The Drawing library paints shapes and text over the Roblox window. In this tutorial you start with one square and end with a box ESP that follows every player, with names and health bars.
How drawing works
You make an object with Drawing.new(kind), set its properties, and it stays on screen until you remove it or the script stops. You never redraw anything yourself. Change a property and the next frame shows the change.
Positions are in pixels inside the Roblox window, with (0, 0) at its top left corner. workspace.CurrentCamera.ViewportSize tells you how big the window is. WorldToScreen uses the same pixels, so its results go straight into a drawing.
Two things trip people up at first:
- A new drawing is hidden. Set
Visible = true. Transparencyis how solid it is:1is fully solid (the default) and0is invisible.
1. A square
local box = Drawing.new("Square")
box.Position = Vector2.new(100, 100)
box.Size = Vector2.new(200, 120)
box.Color = Color3.fromRGB(255, 60, 60)
box.Thickness = 2
box.Visible = true
task.wait(5)
box:Remove()Run it and a red outline shows for five seconds. Set box.Filled = true for a solid square, and box.Corner = 12 to round its corners.
You do not need the Remove call at the end. Stopping the script removes every drawing it made. A script that still has drawings on screen keeps running, so this one would stay until you stop it if you left out the last two lines.
2. Text
local label = Drawing.new("Text")
label.Text = "Hello from evasive"
label.Position = Vector2.new(100, 60)
label.FontSize = 20
label.Font = Drawing.Fonts.SystemBold
label.Outline = true
label.Color = Color3.new(1, 1, 1)
label.Visible = trueCenter = true centres the text on Position.X, which is handy for labels above a player. TextBounds gives you the size of the text in pixels once it has been drawn.
The fonts are Drawing.Fonts.UI, System, SystemBold, Blocky, Monospace, Pixel, Heavy and Rounded. When a font is not installed on your PC, a close Windows font stands in for it.
3. Follow a player
WorldToScreen(position) turns a point in the game into a pixel position. It also tells you whether the point is on screen. Behind the camera it returns (0, 0) and false.
This puts a dot on the nearest other player's root part:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local dot = Drawing.new("Circle")
dot.Radius = 5
dot.Filled = true
dot.Color = Color3.fromRGB(255, 220, 0)
RunService.RenderStepped:Connect(function()
local camera = workspace.CurrentCamera
local best, bestDistance = nil, math.huge
for _, player in ipairs(Players:GetPlayers()) do
local character = player ~= LocalPlayer and player.Character
local root = character and character:FindFirstChild("HumanoidRootPart")
if root then
local distance = (root.Position - camera.Position).Magnitude
if distance < bestDistance then
best, bestDistance = root, distance
end
end
end
if best then
local point, onScreen = WorldToScreen(best.Position)
dot.Position = point
dot.Visible = onScreen
else
dot.Visible = false
end
end)RenderStepped fires once for every frame evasive draws, so the dot moves smoothly.
4. A box around a character
A box needs a top and a bottom. Take the root part's position, go up about three studs for the head and down about three and a half for the feet, and project both:
local function boxFor(root)
local top, topOn = WorldToScreen(root.Position + Vector3.new(0, 3, 0))
local bottom, bottomOn = WorldToScreen(root.Position - Vector3.new(0, 3.5, 0))
if not (topOn and bottomOn) then
return nil
end
local height = bottom.Y - top.Y
local width = height * 0.6
return Vector2.new(top.X - width / 2, top.Y), Vector2.new(width, height)
endThe box grows as the player comes closer, because the two points spread apart on screen. If you want a box that fits the character exactly, character:GetExtentsSize() gives its full size in studs.
5. Every player, with names and health
Now put it together. The script keeps one set of drawings per player, makes them when a player shows up and removes them when the player leaves.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local LocalPlayer = Players.LocalPlayer
local esp = {}
local function create(player)
local box = Drawing.new("Square")
box.Thickness = 1.5
box.Color = Color3.fromRGB(255, 70, 70)
local name = Drawing.new("Text")
name.FontSize = 14
name.Center = true
name.Outline = true
name.Color = Color3.new(1, 1, 1)
local barBack = Drawing.new("Square")
barBack.Filled = true
barBack.Color = Color3.new(0, 0, 0)
barBack.Transparency = 0.6
local bar = Drawing.new("Square")
bar.Filled = true
esp[player] = { box = box, name = name, barBack = barBack, bar = bar }
end
local function destroy(player)
local d = esp[player]
if d then
for _, drawing in pairs(d) do
drawing:Remove()
end
esp[player] = nil
end
end
local function hide(d)
for _, drawing in pairs(d) do
drawing.Visible = false
end
end
local function boxFor(root)
local top, topOn = WorldToScreen(root.Position + Vector3.new(0, 3, 0))
local bottom, bottomOn = WorldToScreen(root.Position - Vector3.new(0, 3.5, 0))
if not (topOn and bottomOn) then
return nil
end
local height = bottom.Y - top.Y
local width = height * 0.6
return Vector2.new(top.X - width / 2, top.Y), Vector2.new(width, height)
end
RunService.RenderStepped:Connect(function()
for player, d in pairs(esp) do
local character = player.Character
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
local root = character and character:FindFirstChild("HumanoidRootPart")
local position, size
if root and humanoid and humanoid.Health > 0 then
position, size = boxFor(root)
end
if position then
d.box.Position = position
d.box.Size = size
d.box.Visible = true
d.name.Text = player.DisplayName
d.name.Position = Vector2.new(position.X + size.X / 2, position.Y - 16)
d.name.Visible = true
local health = math.clamp(humanoid.Health / humanoid.MaxHealth, 0, 1)
d.barBack.Position = Vector2.new(position.X - 6, position.Y)
d.barBack.Size = Vector2.new(3, size.Y)
d.barBack.Visible = true
d.bar.Position = Vector2.new(position.X - 6, position.Y + size.Y * (1 - health))
d.bar.Size = Vector2.new(3, size.Y * health)
d.bar.Color = Color3.fromHSV(health / 3, 1, 1)
d.bar.Visible = true
else
hide(d)
end
end
end)
-- keep the list in step with the server
while true do
local present = {}
for _, player in ipairs(Players:GetPlayers()) do
if player ~= LocalPlayer then
present[player] = true
if not esp[player] then
create(player)
end
end
end
for player in pairs(esp) do
if not present[player] then
destroy(player)
end
end
task.wait(1)
endPlayers work as table keys because the same player is always the same object, and == between two instances compares the objects they point at.
The health bar colour runs from green at full health to red near zero, because Color3.fromHSV(health / 3, 1, 1) moves the hue from a third of the wheel (green) down to zero (red).
What else you can draw
| Kind | Properties you set |
|---|---|
Square |
Position, Size, Filled, Thickness, Corner |
Line |
From, To, Thickness |
Circle |
Position, Radius, Filled, Thickness, NumSides |
Text |
Position, Text, FontSize, Font, Center, Outline, OutlineColor |
Triangle |
PointA, PointB, PointC, Filled, Thickness |
Quad |
PointA, PointB, PointC, PointD, Filled, Thickness |
Image |
Position, Size, Data, Rounding |
Every kind also has Visible, Color, Transparency, ZIndex and Position. A higher ZIndex draws on top.
An Image takes the raw bytes of a PNG, JPEG or BMP file in Data. You can get them from the web with httpget(url) or from your workspace folder with readfile("logo.dat") (save binary files under .dat).
A script can have up to 10000 drawings at a time.