local camera = workspace.CurrentCamera
local entitiesFolder = game:GetService("Workspace").Live
local runService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")
local espEnabled = false
local function esp(entity)
local humanoid = entity:FindFirstChild("Humanoid")
local humanoidRootPart = entity:FindFirstChild("HumanoidRootPart")
if not humanoid or not humanoidRootPart then
return
end
local textLabel = Drawing.new("Text")
textLabel.Visible = false
textLabel.Center = true
textLabel.Outline = true
textLabel.Font = 2
textLabel.Color = Color3.fromRGB(0, 255, 0)
textLabel.Size = 13
local ancestryChangedConnection
local healthChangedConnection
local renderSteppedConnection
local function disconnectConnections()
textLabel.Visible = false
textLabel:Remove()
if ancestryChangedConnection then
ancestryChangedConnection:Disconnect()
ancestryChangedConnection = nil
end
if healthChangedConnection then
healthChangedConnection:Disconnect()
healthChangedConnection = nil
end
if renderSteppedConnection then
renderSteppedConnection:Disconnect()
renderSteppedConnection = nil
end
end
ancestryChangedConnection = entity.AncestryChanged:Connect(function(_, parent)
if not parent then
disconnectConnections()
end
end)
healthChangedConnection = humanoid.HealthChanged:Connect(function(health)
if health <= 0 then
disconnectConnections()
end
end)
renderSteppedConnection = runService.RenderStepped:Connect(function()
local hrpPosition, hrpOnScreen = camera:WorldToViewportPoint(humanoidRootPart.Position)
if hrpOnScreen then
local distance = (camera.CFrame.Position - humanoidRootPart.Position).Magnitude
if distance <= 1000 then -- Adjust the distance threshold as needed
textLabel.Position = Vector2.new(hrpPosition.X, hrpPosition.Y)
textLabel.Text = string.format("%s\nDistance: %.2f\nHealth: %.1f", humanoid.DisplayName, distance, humanoid.Health)
textLabel.Visible = espEnabled
else
textLabel.Visible = false
end
else
textLabel.Visible = false
end
end)
end
local function entityAdded(entity)
if entity:IsA("Model") and not entity:FindFirstChild("Health") then
esp(entity)
end
entity.ChildAdded:Connect(function(child)
if child:IsA("Model") and not child:FindFirstChild("Health") then
esp(child)
end
end)
end
local function toggleESP()
espEnabled = not espEnabled
for _, entity in ipairs(entitiesFolder:GetChildren()) do
if not entity:FindFirstChild("Health") then
entityAdded(entity)
end
end
end
userInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Z then
toggleESP()
end
end)
for _, entity in ipairs(entitiesFolder:GetChildren()) do
if not entity:FindFirstChild("Health") then
entityAdded(entity)
end
end
entitiesFolder.ChildAdded:Connect(entityAdded)