Advertisement
justin18

simple esp roblox script (h to toggle gui)

Aug 6th, 2024
31,452
-1
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | Gaming | 1 2
  1. local colourTable = {
  2. Green = Color3.fromRGB(0, 255, 0),
  3. Blue = Color3.fromRGB(0, 0, 255),
  4. Red = Color3.fromRGB(255, 0, 0),
  5. Yellow = Color3.fromRGB(255, 255, 0),
  6. Orange = Color3.fromRGB(255, 165, 0),
  7. Purple = Color3.fromRGB(128, 0, 128)
  8. }
  9. local colourChosen = colourTable.Red -- Change "Red" to whatever colour you like from the table above, feel free to add other colours as well.
  10. _G.ESPToggle = false -- This is the variable used for enabling/disabling ESP. If you are using a GUI library, or your own custom GUI, then set this variable to the callback function.
  11.  
  12. -- Services and lp
  13. local Players = game:GetService("Players")
  14. local LocalPlayer = Players.LocalPlayer
  15. local RunService = game:GetService("RunService")
  16. local UserInputService = game:GetService("UserInputService")
  17. local Workspace = game:GetService("Workspace")
  18.  
  19. -- The following screen gui, frame and button creation may be deleted if you are using a custom GUI library.
  20. -- Create the screen gui
  21. local screenGui = Instance.new("ScreenGui")
  22. screenGui.Name = "ESPToggleGui"
  23. screenGui.Parent = LocalPlayer:WaitForChild("PlayerGui")
  24.  
  25. -- Create a frame
  26. local mainFrame = Instance.new("Frame")
  27. mainFrame.Name = "MainFrame"
  28. mainFrame.Size = UDim2.new(1, 0, 1, 0)
  29. mainFrame.BackgroundTransparency = 1
  30. mainFrame.Parent = screenGui
  31.  
  32. -- Create the button
  33. local toggleButton = Instance.new("TextButton")
  34. toggleButton.Name = "ToggleButton"
  35. toggleButton.Size = UDim2.new(0, 200, 0, 50)
  36. toggleButton.Position = UDim2.new(0.5, -100, 0.5, -25)
  37. toggleButton.Text = "Toggle ESP"
  38. toggleButton.Parent = mainFrame
  39.  
  40. local function getCharacter(player)
  41. return Workspace:FindFirstChild(player.Name)
  42. end
  43.  
  44. -- Add highlights to players
  45. local function addHighlightToCharacter(player, character)
  46. if player == LocalPlayer then return end -- Skip local player
  47. local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  48. if humanoidRootPart and not humanoidRootPart:FindFirstChild("Highlight") then
  49. local highlightClone = Instance.new("Highlight") -- Create a new Highlight instance
  50. highlightClone.Name = "Highlight"
  51. highlightClone.Adornee = character
  52. highlightClone.Parent = humanoidRootPart
  53. highlightClone.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
  54. highlightClone.FillColor = colourChosen
  55. highlightClone.OutlineColor = Color3.fromRGB(255, 255, 255)
  56. highlightClone.FillTransparency = 0.5
  57. end
  58. end
  59.  
  60. -- Remove highlights from player
  61. local function removeHighlightFromCharacter(character)
  62. local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  63. if humanoidRootPart then
  64. local highlightInstance = humanoidRootPart:FindFirstChild("Highlight")
  65. if highlightInstance then
  66. highlightInstance:Destroy()
  67. end
  68. end
  69. end
  70.  
  71. -- Function to update highlights based on the value of _G.ESPToggle
  72. local function updateHighlights()
  73. for _, player in pairs(Players:GetPlayers()) do
  74. local character = getCharacter(player)
  75. if character then
  76. if _G.ESPToggle then
  77. addHighlightToCharacter(player, character)
  78. else
  79. removeHighlightFromCharacter(character)
  80. end
  81. end
  82. end
  83. end
  84.  
  85. -- Connect events through RenderStepped to loop
  86. RunService.RenderStepped:Connect(function()
  87. updateHighlights()
  88. end)
  89.  
  90. -- Add highlight to joining players
  91. Players.PlayerAdded:Connect(function(player)
  92. player.CharacterAdded:Connect(function(character)
  93. if _G.ESPToggle then
  94. addHighlightToCharacter(player, character)
  95. end
  96. end)
  97. end)
  98.  
  99. -- Remove highlights from leaving players
  100. Players.PlayerRemoving:Connect(function(playerRemoved)
  101. local character = playerRemoved.Character
  102. if character then
  103. removeHighlightFromCharacter(character)
  104. end
  105. end)
  106.  
  107. -- The following code may be deleted if you are using a custom GUI library.
  108.  
  109. -- Toggle ESP Button Text based on variable status
  110. toggleButton.MouseButton1Click:Connect(function()
  111. _G.ESPToggle = not _G.ESPToggle
  112. if _G.ESPToggle then
  113. toggleButton.Text = "ESP ON"
  114. else
  115. toggleButton.Text = "ESP OFF"
  116. end
  117. end)
  118.  
  119. -- Initial button text
  120. if _G.ESPToggle then
  121. toggleButton.Text = "ESP ON"
  122. else
  123. toggleButton.Text = "ESP OFF"
  124. end
  125.  
  126. -- Keybind to toggle GUI visibility
  127. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  128. if input.KeyCode == Enum.KeyCode.H and not gameProcessed then -- Change Enum.KeyCode.H to another key if you want to, e.g. Enum.KeyCode.P for "P" Key.
  129. mainFrame.Visible = not mainFrame.Visible
  130. end
  131. end)
Tags: exploits
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement