Advertisement
AERQ1111

ROBLOX Simple Player ESP Script (FIXED)

Feb 26th, 2025 (edited)
3,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.18 KB | None | 0 0
  1. -- Simple player highlighting and nametag script with toggle feature now
  2. local Players = game:GetService("Players")
  3. local RunService = game:GetService("RunService")
  4. local UserInputService = game:GetService("UserInputService")
  5. local LocalPlayer = Players.LocalPlayer
  6. local MaxDistance = 400.5 -- Range in studs for nametags to show
  7.  
  8. -- Toggle variable
  9. local NametagsEnabled = true
  10.  
  11. -- Function to create a nametag for a player
  12. local function CreateNametag(Player)
  13.     if Player == LocalPlayer then return end -- Skip local player
  14.  
  15.     local function SetupNametag(Character)
  16.         local Head = Character:FindFirstChild("Head")
  17.         if not Head then return end -- If no head, exit
  18.  
  19.         -- Remove existing nametag if it exists
  20.         local OldNametag = Head:FindFirstChild("Nametag")
  21.         if OldNametag then
  22.             OldNametag:Destroy()
  23.         end
  24.  
  25.         local BillboardGui = Instance.new("BillboardGui")
  26.         BillboardGui.Name = "Nametag"
  27.         BillboardGui.Adornee = Head
  28.         BillboardGui.Size = UDim2.new(0, 75, 0, 150)
  29.         BillboardGui.StudsOffset = Vector3.new(0, 2, 0)
  30.         BillboardGui.AlwaysOnTop = true
  31.  
  32.         local TextLabel = Instance.new("TextLabel")
  33.         TextLabel.Size = UDim2.new(1, 0, 1, 0)
  34.         TextLabel.Text = Player.Name
  35.         TextLabel.TextColor3 = Color3.fromRGB(255, 255, 255) -- White color
  36.         TextLabel.BackgroundTransparency = 1
  37.         TextLabel.TextStrokeTransparency = 0.75 -- Outline for better visibility
  38.         TextLabel.Font = Enum.Font.Code
  39.         TextLabel.TextScaled = true
  40.         TextLabel.Parent = BillboardGui
  41.  
  42.         BillboardGui.Parent = Head
  43.  
  44.         -- Function to update visibility based on distance and toggle
  45.         local function UpdateVisibility()
  46.             if NametagsEnabled and Player.Character and Player.Character:FindFirstChild("Head") and LocalPlayer.Character and LocalPlayer.Character:FindFirstChild("Head") then
  47.                 local Distance = (Player.Character.Head.Position - LocalPlayer.Character.Head.Position).Magnitude
  48.                 BillboardGui.Enabled = (Distance <= MaxDistance)
  49.             else
  50.                 BillboardGui.Enabled = false
  51.             end
  52.         end
  53.  
  54.         -- Monitor visibility
  55.         local Connection
  56.         Connection = RunService.Heartbeat:Connect(function()
  57.             if Player.Character and Player.Character:FindFirstChild("Head") then
  58.                 UpdateVisibility()
  59.             else
  60.                 BillboardGui:Destroy() -- Clean up nametag when player dies
  61.                 Connection:Disconnect()
  62.             end
  63.         end)
  64.     end
  65.  
  66.     -- Apply when character spawns or respawns
  67.     if Player.Character then
  68.         SetupNametag(Player.Character)
  69.     end
  70.     Player.CharacterAdded:Connect(SetupNametag)
  71. end
  72.  
  73. -- Function to apply ESP/Highlight to a player
  74. local function ApplyHighlight(Player)
  75.     if Player == LocalPlayer then return end -- Skip local player
  76.  
  77.     local function SetupHighlight(Character)
  78.         -- Remove old highlights
  79.         for _, v in pairs(Character:GetChildren()) do
  80.             if v:IsA("Highlight") then
  81.                 v:Destroy()
  82.             end
  83.         end
  84.  
  85.         local Highlighter = Instance.new("Highlight")
  86.         Highlighter.Parent = Character
  87.  
  88.         local function UpdateFillColor()
  89.             local DefaultColor = Color3.fromRGB(255, 48, 51) -- Default red color
  90.             Highlighter.FillColor = Player.TeamColor and Player.TeamColor.Color or DefaultColor
  91.         end
  92.  
  93.         UpdateFillColor()
  94.         Player:GetPropertyChangedSignal("TeamColor"):Connect(UpdateFillColor)
  95.  
  96.         -- Remove highlight when player dies
  97.         local Humanoid = Character:FindFirstChildOfClass("Humanoid")
  98.         if Humanoid then
  99.             Humanoid.Died:Connect(function()
  100.                 Highlighter:Destroy()
  101.             end)
  102.         end
  103.     end
  104.  
  105.     -- Apply highlight on spawn and respawn
  106.     if Player.Character then
  107.         SetupHighlight(Player.Character)
  108.     end
  109.     Player.CharacterAdded:Connect(SetupHighlight)
  110. end
  111.  
  112. -- Function to toggle nametags
  113. local function ToggleNametags()
  114.     NametagsEnabled = not NametagsEnabled -- Flip the toggle state
  115.     print("Nametags Enabled:", NametagsEnabled)
  116.  
  117.     for _, Player in pairs(Players:GetPlayers()) do
  118.         if Player ~= LocalPlayer and Player.Character and Player.Character:FindFirstChild("Head") then
  119.             local Nametag = Player.Character.Head:FindFirstChild("Nametag")
  120.             if Nametag then
  121.                 Nametag.Enabled = NametagsEnabled
  122.             end
  123.         end
  124.     end
  125. end
  126.  
  127. -- Bind the toggle function to the "[" key
  128. UserInputService.InputBegan:Connect(function(Input, GameProcessed)
  129.     if not GameProcessed and Input.KeyCode == Enum.KeyCode.LeftBracket then
  130.         ToggleNametags()
  131.     end
  132. end)
  133.  
  134. -- Apply ESP and Nametags to all current players
  135. for _, Player in pairs(Players:GetPlayers()) do
  136.     CreateNametag(Player)
  137.     ApplyHighlight(Player)
  138. end
  139.  
  140. -- Apply ESP and Nametags to players who join later
  141. Players.PlayerAdded:Connect(function(Player)
  142.     CreateNametag(Player)
  143.     ApplyHighlight(Player)
  144. end)
  145. -- 4/3/2025 X:XXPM (Script Updated)
  146. -- 4/4/2025 1:59PM (Edit / Update)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement