Advertisement
Chuffman-CSD

[Roblox] - ESP GUI

Jul 29th, 2023 (edited)
3,239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.64 KB | Gaming | 0 0
  1. local playerGui = game.Players.LocalPlayer:WaitForChild("PlayerGui")
  2.  
  3. -- check if the ScreenGui already exists, if it does, destroy it and remove BillboardGuis
  4. if playerGui:FindFirstChild("TadachiisESP") then
  5.     playerGui:FindFirstChild("TadachiisESP"):Destroy()
  6.  
  7.     for _, player in ipairs(game.Players:GetPlayers()) do
  8.         local billboardGui = player.Character and player.Character:FindFirstChild("Head") and player.Character.Head:FindFirstChild("PlayerBillboardGui")
  9.         if billboardGui then
  10.             billboardGui:Destroy()
  11.         end
  12.     end
  13. end
  14.  
  15. -- create ScreenGui
  16. local screenGui = Instance.new("ScreenGui")
  17. screenGui.Name = "TadachiisESP"
  18. screenGui.Parent = playerGui
  19. screenGui.DisplayOrder = 1
  20.  
  21. -- create Frame
  22. local holder = Instance.new("Frame")
  23. holder.Name = "Holder"
  24. holder.Parent = screenGui
  25. holder.Size = UDim2.new(0, 200, 0, 100) -- size of the frame
  26. holder.Position = UDim2.new(0.5, -100, 0.5, -50) -- position of the frame at the center of the screen
  27. holder.BackgroundColor3 = Color3.new(1, 1, 1) -- white background
  28. holder.BackgroundTransparency = 0.5 -- semi-transparent
  29. holder.Draggable = true -- makes the frame draggable
  30. holder.Active = true
  31.  
  32. -- create TextLabel
  33. local titleLabel = Instance.new("TextLabel")
  34. titleLabel.Name = "TitleLabel"
  35. titleLabel.Text = "Tadachii's ESP GUI"
  36. titleLabel.TextScaled = true
  37. titleLabel.Parent = holder
  38. titleLabel.Size = UDim2.new(1, 0, 0.5, 0) -- fills half of the frame
  39. titleLabel.BackgroundColor3 = Color3.new(1, 1, 1) -- white background
  40. titleLabel.TextColor3 = Color3.new(0, 0, 0) -- black text
  41. titleLabel.BackgroundTransparency = 0.5 -- semi-transparent
  42.  
  43. -- create TextLabel for Status
  44. local statusLabel = Instance.new("TextLabel")
  45. statusLabel.Name = "StatusLabel"
  46. statusLabel.Text = ""
  47. statusLabel.Parent = holder
  48. statusLabel.Size = UDim2.new(1, 0, 0.25, 0) -- fills one-fourth of the frame below the TitleLabel
  49. statusLabel.Position = UDim2.new(0, 0, 0.5, 0) -- aligns the text label to the bottom of the frame
  50. statusLabel.BackgroundColor3 = Color3.new(1, 1, 1) -- white background
  51. statusLabel.TextColor3 = Color3.new(0, 0, 0) -- black text
  52. statusLabel.BackgroundTransparency = 0.5 -- semi-transparent
  53. statusLabel.TextScaled = true -- enable text scaling for the status label
  54.  
  55. -- create TextButton for Status
  56. local statusButton = Instance.new("TextButton")
  57. statusButton.Name = "StatusButton"
  58. statusButton.Text = "Off"
  59. statusButton.Parent = holder
  60. statusButton.Size = UDim2.new(1, 0, 0.25, 0) -- fills one-fourth of the frame below the StatusLabel
  61. statusButton.Position = UDim2.new(0, 0, 0.75, 0) -- aligns the button to the bottom of the frame
  62. statusButton.BackgroundColor3 = Color3.new(1, 1, 1) -- white background
  63. statusButton.TextColor3 = Color3.new(0, 0, 0) -- black text
  64. statusButton.BackgroundTransparency = 0.5 -- semi-transparent
  65. statusButton.TextScaled = true -- enable text scaling for the button
  66.  
  67. -- Function to create BillboardGui for a player with name and distance
  68. local function createBillboardGuiForPlayer(player, distance)
  69.     local billboardGui = Instance.new("BillboardGui")
  70.     billboardGui.Name = "PlayerBillboardGui"
  71.     billboardGui.Adornee = player.Character.Head
  72.     billboardGui.Size = UDim2.new(0, 100, 0, 50) -- fixed size for the BillboardGui
  73.     billboardGui.StudsOffset = Vector3.new(0, 2, 0) -- adjust the vertical offset as needed
  74.     billboardGui.AlwaysOnTop = true
  75.     billboardGui.LightInfluence = 1
  76.     billboardGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  77.     billboardGui.Parent = player.Character.Head
  78.  
  79.     local textLabel = Instance.new("TextLabel")
  80.     textLabel.Name = "PlayerNameLabel"
  81.     textLabel.Text = player.Name .. "\nDistance: " .. math.floor(distance)
  82.     textLabel.Size = UDim2.new(1, 0, 1, 0)
  83.     textLabel.BackgroundTransparency = 1 -- transparent background
  84.     textLabel.TextColor3 = Color3.new(1, 0, 0) -- red text for the player's name
  85.     textLabel.TextScaled = true
  86.     textLabel.TextStrokeColor3 = Color3.new(0, 0, 0) -- black text stroke
  87.     textLabel.TextStrokeTransparency = 0 -- fully opaque text stroke (visible through walls)
  88.     textLabel.Visible = statusButton.Text == "On" -- Hide the text if StatusButton is "Off"
  89.     textLabel.Parent = billboardGui
  90. end
  91.  
  92. -- Function to update player ESP distance
  93. local function updatePlayerESP()
  94.     local localCharacter = game.Players.LocalPlayer.Character
  95.     if not localCharacter then
  96.         return
  97.     end
  98.  
  99.     for _, player in ipairs(game.Players:GetPlayers()) do
  100.         if player ~= game.Players.LocalPlayer and player.Character and player.Character:FindFirstChild("Head") then
  101.             local distance = (localCharacter.Head.Position - player.Character.Head.Position).Magnitude
  102.             local billboardGui = player.Character.Head:FindFirstChild("PlayerBillboardGui")
  103.             if billboardGui then
  104.                 billboardGui.PlayerNameLabel.Text = player.Name .. "\nDistance: " .. math.floor(distance)
  105.                 billboardGui.PlayerNameLabel.TextColor3 = Color3.new(1, 0, 0) -- Set the text color to red
  106.                 billboardGui.PlayerNameLabel.Visible = statusButton.Text == "On" -- Update visibility based on StatusButton
  107.             else
  108.                 createBillboardGuiForPlayer(player, distance)
  109.             end
  110.         end
  111.     end
  112. end
  113.  
  114. -- Call updatePlayerESP() initially and then schedule it to be called every 0.01 seconds
  115. updatePlayerESP()
  116. game:GetService("RunService").Heartbeat:Connect(function()
  117.     updatePlayerESP()
  118. end)
  119.  
  120. -- Now, you can add functionality to the button, for example:
  121. local function onButtonClicked()
  122.     if statusButton.Text == "Off" then
  123.         statusButton.Text = "On"
  124.         -- Add code to enable the player ESP here
  125.     else
  126.         statusButton.Text = "Off"
  127.         -- Add code to disable the player ESP here
  128.        
  129.         -- Remove BillboardGui for each player's head when disabling the ESP
  130.         for _, player in ipairs(game.Players:GetPlayers()) do
  131.             local billboardGui = player.Character and player.Character:FindFirstChild("Head") and player.Character.Head:FindFirstChild("PlayerBillboardGui")
  132.             if billboardGui then
  133.                 billboardGui:Destroy()
  134.             end
  135.         end
  136.     end
  137.     -- Update the visibility of BillboardGui elements after clicking the button
  138.     for _, player in ipairs(game.Players:GetPlayers()) do
  139.         local billboardGui = player.Character and player.Character:FindFirstChild("Head") and player.Character.Head:FindFirstChild("PlayerBillboardGui")
  140.         if billboardGui then
  141.             billboardGui.PlayerNameLabel.Visible = statusButton.Text == "On"
  142.         end
  143.     end
  144. end
  145.  
  146. statusButton.MouseButton1Click:Connect(onButtonClicked)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement