
Key RequiredUniversal

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local HIGHLIGHT_NAME = "ESPHighlight" -- Unique name for our highlight instance
-- Function to set up highlight for a character
local function setupCharacterHighlight(character)
-- Ensure character is valid and doesn't already have our highlight
if not character or character:FindFirstChild(HIGHLIGHT_NAME) then
return
end
local highlight = Instance.new("Highlight")
highlight.Name = HIGHLIGHT_NAME
highlight.Adornee = character
highlight.FillColor = Color3.fromRGB(255, 0, 0) -- Bright Red fill
highlight.OutlineColor = Color3.fromRGB(255, 255, 255) -- White outline
highlight.FillTransparency = 0.6 -- Semi-transparent fill
highlight.OutlineTransparency = 0.2 -- Slightly transparent outline
highlight.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop -- Visible through walls and objects
highlight.Enabled = true
highlight.Parent = character -- Parent to character for automatic cleanup
-- Connect to character's Destroying event to clean up the connection itself.
-- The Highlight instance is automatically destroyed due to being parented to the character.
local charDestroyingConnection
charDestroyingConnection = character.Destroying:Connect(function()
if charDestroyingConnection then
charDestroyingConnection:Disconnect()
end
end)
end
-- Function to handle player joining or already being present
local function onPlayerProcessed(player)
-- Do not highlight the local player
if player == LocalPlayer then
-- Ensure local player's character (if any) doesn't have this highlight
local function removeHighlightFromLocalPlayerCharacter(character)
if character then
local existingHighlight = character:FindFirstChild(HIGHLIGHT_NAME)
if existingHighlight then
existingHighlight:Destroy()
end
end
end
if player.Character then
removeHighlightFromLocalPlayerCharacter(player.Character)
end
player.CharacterAdded:Connect(removeHighlightFromLocalPlayerCharacter)
return
end
-- If the player's character already exists, set up the highlight
if player.Character then
setupCharacterHighlight(player.Character)
end
-- Connect to CharacterAdded event for when the player's character spawns/respawns
player.CharacterAdded:Connect(function(character)
setupCharacterHighlight(character)
end)
end
-- Process all players already in the game when the script starts
for _, player in Players:GetPlayers() do
onPlayerProcessed(player)
end
-- Process players who join the game later
Players.PlayerAdded:Connect(onPlayerProcessed)
-- No specific Players.PlayerRemoving logic is needed for the highlight instances themselves,
-- as parenting them to the character handles their destruction when the character is removed.



ai