
Key Required Patched

print("[ESP] Script starting")
-- ═══════════════════════════════════════════════════════════════
-- HOT-RELOAD CLEANUP
-- ═══════════════════════════════════════════════════════════════
if getgenv().__APX_ESP_CLEANUP then
getgenv().__APX_ESP_CLEANUP()
getgenv().__APX_ESP_CLEANUP = nil
task.wait()
end
-- ═══════════════════════════════════════════════════════════════
-- SERVICES & LOCALS
-- ═══════════════════════════════════════════════════════════════
local Workspace = cloneref(workspace)
local Players = cloneref(game:GetService("Players"))
local RunService = cloneref(game:GetService("RunService"))
local UserInputService = cloneref(game:GetService("UserInputService"))
local LocalPlayer = Players.LocalPlayer
local CurrentCamera = Workspace.CurrentCamera
local Instance_new = Instance.new
local UDim2_new = UDim2.new
local Color3_fromRGB = Color3.fromRGB
local mathFloor = math.floor
local mathClamp = math.clamp
-- ═══════════════════════════════════════════════════════════════
-- CONFIG
-- ═══════════════════════════════════════════════════════════════
local CONFIG = {
MaxDistance = 500,
TextColor = Color3_fromRGB(255, 255, 255),
BoxColor = Color3_fromRGB(255, 0, 0),
BoxFillColor = Color3_fromRGB(255, 0, 0),
HealthBarGood = Color3_fromRGB(0, 255, 0),
HealthBarBad = Color3_fromRGB(255, 0, 0),
TracerColor = Color3_fromRGB(255, 255, 255),
BoxThickness = 1,
BoxFillTransparency = 0.85,
BoxOutlineTransparency = 0,
TracerTransparency = 0.5,
ShowBox = true,
ShowHealthBar = true,
ShowTracer = true,
ShowDistance = true,
ShowName = true,
ShowHealthText = true,
}
-- ═══════════════════════════════════════════════════════════════
-- STATE
-- ═══════════════════════════════════════════════════════════════
local _enabled = true
local _connections = {}
local _espCache = {} -- model -> { gui = {...} }
local _aiModels = {} -- [model] = true (event-driven set)
local _trackedFolder = nil
local _screenGui = gethui():FindFirstChild("APX_ESP_GUI")
if _screenGui then _screenGui:Destroy() end
_screenGui = Instance_new("ScreenGui")
_screenGui.Name = "APX_ESP_GUI"
_screenGui.ResetOnSpawn = false
_screenGui.IgnoreGuiInset = true
_screenGui.DisplayOrder = 9999
_screenGui.Parent = gethui()
print("[ESP] GUI created")
-- ═══════════════════════════════════════════════════════════════
-- HELPERS
-- ═══════════════════════════════════════════════════════════════
local function lerpColor(a, b, t)
return Color3_fromRGB(
mathFloor(a.R * 255 + (b.R - a.R) * 255 * t),
mathFloor(a.G * 255 + (b.G - a.G) * 255 * t),
mathFloor(a.B * 255 + (b.B - a.B) * 255 * t)
)
end
local function isAlive(model)
local hum = model:FindFirstChildOfClass("Humanoid")
return hum and hum.Health > 0
end
-- ═══════════════════════════════════════════════════════════════
-- AI FOLDER TRACKING (no per-frame scanning)
-- ═══════════════════════════════════════════════════════════════
local function onAIModelAdded(model)
if model:IsA("Model") then
_aiModels[model] = true
end
end
local function onAIModelRemoved(model)
if not _aiModels[model] then return end
_aiModels[model] = nil
local data = _espCache[model]
if data then
pcall(function() data.gui.container:Destroy() end)
_espCache[model] = nil
end
end
local function startTrackingAIFolder(folder)
if _trackedFolder == folder then return end
_trackedFolder = folder
-- wipe old state when switching folders
for model in pairs(_aiModels) do
_aiModels[model] = nil
end
for model, data in pairs(_espCache) do
pcall(function() data.gui.container:Destroy() end)
_espCache[model] = nil
end
-- seed existing children
for _, child in ipairs(folder:GetChildren()) do
onAIModelAdded(child)
end
-- events
table.insert(_connections, folder.ChildAdded:Connect(onAIModelAdded))
table.insert(_connections, folder.ChildRemoved:Connect(onAIModelRemoved))
end
local function initAITracking()
local world = Workspace:FindFirstChild("World")
if world then
local ai = world:FindFirstChild("AI")
if ai then
startTrackingAIFolder(ai)
return
end
-- World exists, AI doesn't yet
table.insert(_connections, world.ChildAdded:Connect(function(child)
if child.Name == "AI" and child:IsA("Folder") then
startTrackingAIFolder(child)
end
end))
else
-- Wait for World folder
table.insert(_connections, Workspace.ChildAdded:Connect(function(child)
if child.Name == "World" then
initAITracking() -- retry now that World exists
end
end))
end
end
initAITracking()
-- ═══════════════════════════════════════════════════════════════
-- GUI CREATION
-- ═══════════════════════════════════════════════════════════════
local function createESPGui(model)
local container = Instance_new("Frame")
container.Name = "ESP_" .. model.Name
container.BackgroundTransparency = 1
container.BorderSizePixel = 0
container.Size = UDim2_new(0, 0, 0, 0)
container.Visible = false
container.Parent = _screenGui
-- Box outline
local boxOutline = Instance_new("Frame")
boxOutline.Name = "BoxOutline"
boxOutline.BackgroundTransparency = 1
boxOutline.BorderSizePixel = 0
boxOutline.Visible = false
boxOutline.Parent = container
local boxStroke = Instance_new("UIStroke")
boxStroke.Name = "Stroke"
boxStroke.Color = CONFIG.BoxColor
boxStroke.Thickness = CONFIG.BoxThickness + 1
boxStroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
boxStroke.Parent = boxOutline
-- Box fill
local boxFill = Instance_new("Frame")
boxFill.Name = "BoxFill"
boxFill.BackgroundColor3 = CONFIG.BoxFillColor
boxFill.BackgroundTransparency = CONFIG.BoxFillTransparency
boxFill.BorderSizePixel = 0
boxFill.Visible = false
boxFill.Parent = boxOutline
-- Health bar background
local healthBg = Instance_new("Frame")
healthBg.Name = "HealthBg"
healthBg.BackgroundColor3 = Color3_fromRGB(0, 0, 0)
healthBg.BackgroundTransparency = 0.3
healthBg.BorderSizePixel = 0
healthBg.Visible = false
healthBg.Parent = container
-- Health bar fill
local healthFill = Instance_new("Frame")
healthFill.Name = "HealthFill"
healthFill.BackgroundColor3 = CONFIG.HealthBarGood
healthFill.BorderSizePixel = 0
healthFill.Visible = false
healthFill.Parent = healthBg
-- Info text
local textLabel = Instance_new("TextLabel")
textLabel.Name = "InfoText"
textLabel.BackgroundTransparency = 1
textLabel.TextColor3 = CONFIG.TextColor
textLabel.TextSize = 12
textLabel.Font = Enum.Font.GothamBold
textLabel.TextXAlignment = Enum.TextXAlignment.Center
textLabel.TextStrokeTransparency = 0.5
textLabel.TextStrokeColor3 = Color3_fromRGB(0, 0, 0)
textLabel.Size = UDim2_new(0, 200, 0, 20)
textLabel.Visible = false
textLabel.Parent = container
-- Tracer
local tracer = Instance_new("Frame")
tracer.Name = "Tracer"
tracer.BackgroundColor3 = CONFIG.TracerColor
tracer.BorderSizePixel = 0
tracer.Visible = false
tracer.Parent = container
return {
container = container,
boxOutline = boxOutline,
boxFill = boxFill,
healthBg = healthBg,
healthFill = healthFill,
textLabel = textLabel,
tracer = tracer,
}
end
-- ═══════════════════════════════════════════════════════════════
-- UPDATE LOGIC
-- ═══════════════════════════════════════════════════════════════
local function updateESP(model, data)
local gui = data.gui
if not model.Parent or not isAlive(model) then
gui.container.Visible = false
return
end
local root = model:FindFirstChild("HumanoidRootPart")
if not root then
gui.container.Visible = false
return
end
local myChar = LocalPlayer.Character
local myRoot = myChar and myChar:FindFirstChild("HumanoidRootPart")
if not myRoot then
gui.container.Visible = false
return
end
local dist = (root.Position - myRoot.Position).Magnitude
if dist > CONFIG.MaxDistance then
gui.container.Visible = false
return
end
local pos, onScreen = CurrentCamera:WorldToViewportPoint(root.Position)
if not onScreen or pos.Z <= 0 then
gui.container.Visible = false
return
end
local head = model:FindFirstChild("Head")
local topPos = head and CurrentCamera:WorldToViewportPoint(head.Position) or pos
local height = math.abs(pos.Y - topPos.Y) * 1.8
local width = height * 0.55
if height < 20 then height = 20 end
if width < 10 then width = 10 end
local centerX = mathFloor(pos.X)
local centerY = mathFloor(pos.Y)
local boxX = mathFloor(centerX - width / 2)
local boxY = mathFloor(centerY - height / 2)
gui.container.Visible = true
-- Box
if CONFIG.ShowBox then
gui.boxOutline.Visible = true
gui.boxFill.Visible = true
gui.boxOutline.Position = UDim2_new(0, boxX, 0, boxY)
gui.boxOutline.Size = UDim2_new(0, width, 0, height)
gui.boxFill.Size = UDim2_new(1, 0, 1, 0)
else
gui.boxOutline.Visible = false
end
-- Health bar
local hum = model:FindFirstChildOfClass("Humanoid")
local health = hum and mathFloor(hum.Health) or 0
local maxHealth = hum and mathFloor(hum.MaxHealth) or 100
local hpPct = mathClamp(health / maxHealth, 0, 1)
if CONFIG.ShowHealthBar then
gui.healthBg.Visible = true
gui.healthFill.Visible = true
local barW, barH = 3, height
gui.healthBg.Position = UDim2_new(0, boxX - barW - 2, 0, boxY)
gui.healthBg.Size = UDim2_new(0, barW, 0, barH)
gui.healthFill.Size = UDim2_new(1, 0, hpPct, 0)
gui.healthFill.Position = UDim2_new(0, 0, 1 - hpPct, 0)
gui.healthFill.BackgroundColor3 = lerpColor(CONFIG.HealthBarBad, CONFIG.HealthBarGood, hpPct)
else
gui.healthBg.Visible = false
end
-- Tracer
if CONFIG.ShowTracer then
gui.tracer.Visible = true
local vp = CurrentCamera.ViewportSize
local dx = centerX - vp.X / 2
local dy = centerY - vp.Y
local len = math.sqrt(dx * dx + dy * dy)
gui.tracer.Position = UDim2_new(0, vp.X / 2, 0, vp.Y)
gui.tracer.Size = UDim2_new(0, len, 0, 1)
gui.tracer.Rotation = math.deg(math.atan2(dy, dx))
else
gui.tracer.Visible = false
end
-- Text
local parts = {}
if CONFIG.ShowName then table.insert(parts, model.Name) end
if CONFIG.ShowHealthText then table.insert(parts, health .. "/" .. maxHealth) end
if CONFIG.ShowDistance then table.insert(parts, "[" .. mathFloor(dist) .. "m]") end
gui.textLabel.Text = table.concat(parts, " ")
gui.textLabel.Position = UDim2_new(0, centerX - 100, 0, boxY - 22)
gui.textLabel.Visible = true
end
-- ═══════════════════════════════════════════════════════════════
-- RENDER LOOP (iterates cached set, zero folder scanning)
-- ═══════════════════════════════════════════════════════════════
local _renderConn = RunService.PreRender:Connect(function()
if not _enabled then
for _, data in pairs(_espCache) do
data.gui.container.Visible = false
end
return
end
for model in pairs(_aiModels) do
local data = _espCache[model]
if not data then
data = { gui = createESPGui(model) }
_espCache[model] = data
end
updateESP(model, data)
end
end)
table.insert(_connections, _renderConn)
-- ═══════════════════════════════════════════════════════════════
-- CLEANUP
-- ═══════════════════════════════════════════════════════════════
local function cleanup()
_enabled = false
for _, conn in ipairs(_connections) do
pcall(function() conn:Disconnect() end)
end
table.clear(_connections)
for _, data in pairs(_espCache) do
pcall(function() data.gui.container:Destroy() end)
end
table.clear(_espCache)
table.clear(_aiModels)
_trackedFolder = nil
if _screenGui and _screenGui.Parent then
_screenGui:Destroy()
end
getgenv().__APX_ESP_CLEANUP = nil
print("[ESP] Cleaned up")
end
getgenv().__APX_ESP_CLEANUP = cleanup
-- ═══════════════════════════════════════════════════════════════
-- INPUT
-- ═══════════════════════════════════════════════════════════════
local _inputConn = UserInputService.InputBegan:Connect(function(input, gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.Delete then
cleanup()
end
end)
table.insert(_connections, _inputConn)No comments yet for this script.


