1. local camera = workspace.CurrentCamera
  2. local entitiesFolder = workspace.Entities
  3. local runService = game:GetService("RunService")
  4. local userInputService = game:GetService("UserInputService")
  5. local espEnabled = false
  6. local function esp(entity)
  7. local humanoid = entity:FindFirstChild("Humanoid")
  8. local humanoidRootPart = entity:FindFirstChild("HumanoidRootPart")
  9. if not humanoid or not humanoidRootPart then
  10. return
  11. end
  12. local textLabel = Drawing.new("Text")
  13. textLabel.Visible = false
  14. textLabel.Center = true
  15. textLabel.Outline = true
  16. textLabel.Font = 2
  17. textLabel.Color = Color3.fromRGB(0, 255, 0)
  18. textLabel.Size = 13
  19. local ancestryChangedConnection
  20. local healthChangedConnection
  21. local renderSteppedConnection
  22. local function disconnectConnections()
  23. textLabel.Visible = false
  24. textLabel:Remove()
  25. if ancestryChangedConnection then
  26. ancestryChangedConnection:Disconnect()
  27. ancestryChangedConnection = nil
  28. end
  29. if healthChangedConnection then
  30. healthChangedConnection:Disconnect()
  31. healthChangedConnection = nil
  32. end
  33. if renderSteppedConnection then
  34. renderSteppedConnection:Disconnect()
  35. renderSteppedConnection = nil
  36. end
  37. end
  38. ancestryChangedConnection = entity.AncestryChanged:Connect(function(_, parent)
  39. if not parent then
  40. disconnectConnections()
  41. end
  42. end)
  43. healthChangedConnection = humanoid.HealthChanged:Connect(function(health)
  44. if health <= 0 then
  45. disconnectConnections()
  46. end
  47. end)
  48. renderSteppedConnection = runService.RenderStepped:Connect(function()
  49. local hrpPosition, hrpOnScreen = camera:WorldToViewportPoint(humanoidRootPart.Position)
  50. if hrpOnScreen then
  51. textLabel.Position = Vector2.new(hrpPosition.X, hrpPosition.Y)
  52. textLabel.Text = entity.Name
  53. textLabel.Visible = espEnabled
  54. else
  55. textLabel.Visible = false
  56. end
  57. end)
  58. end
  59. local function entityAdded(entity)
  60. if entity:IsA("Model") and not entity:FindFirstChild("Health") then
  61. esp(entity)
  62. end
  63. entity.ChildAdded:Connect(function(child)
  64. if child:IsA("Model") and not child:FindFirstChild("Health") then
  65. esp(child)
  66. end
  67. end)
  68. end
  69. local function toggleESP()
  70. espEnabled = not espEnabled
  71. for _, entity in ipairs(entitiesFolder:GetChildren()) do
  72. if not entity:FindFirstChild("Health") then
  73. entityAdded(entity)
  74. end
  75. end
  76. end
  77. userInputService.InputBegan:Connect(function(input)
  78. if input.KeyCode == Enum.KeyCode.F then
  79. toggleESP()
  80. end
  81. end)
  82. for _, entity in ipairs(entitiesFolder:GetChildren()) do
  83. if not entity:FindFirstChild("Health") then
  84. entityAdded(entity)
  85. end
  86. end
  87. entitiesFolder.ChildAdded:Connect(entityAdded)