Advertisement
kingmohamed

esp

Jan 19th, 2025 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.74 KB | None | 0 0
  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"] -- Set your preferred colour here
  10. _G.ESPToggle = false -- Variable to toggle ESP
  11.  
  12. -- Services and player references
  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. -- Screen GUI setup
  20. local screenGui = Instance.new("ScreenGui")
  21. screenGui.Name = "ESPToggleGui"
  22. screenGui.Parent = game.CoreGui
  23.  
  24. local mainFrame = Instance.new("Frame")
  25. mainFrame.Name = "MainFrame"
  26. mainFrame.Size = UDim2.new(1, 0, 1, 0)
  27. mainFrame.BackgroundTransparency = 1
  28. mainFrame.Parent = screenGui
  29.  
  30. local toggleButton = Instance.new("TextButton")
  31. toggleButton.Name = "ToggleButton"
  32. toggleButton.Size = UDim2.new(0, 200, 0, 50)
  33. toggleButton.Position = UDim2.new(0.5, -100, 0.5, -25)
  34. toggleButton.Text = "Toggle ESP"
  35. toggleButton.Parent = mainFrame
  36.  
  37. local function getCharacter(player)
  38.     return player.Character or Workspace:FindFirstChild(player.Name)
  39. end
  40.  
  41. -- Checks if a player is on the same team as the local player
  42. local function isEnemy(player)
  43.     if not player.Team or not LocalPlayer.Team then return true end
  44.     return player.Team ~= LocalPlayer.Team
  45. end
  46.  
  47. local function addHighlightToCharacter(player, character)
  48.     if player == LocalPlayer or not isEnemy(player) then return end
  49.     local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  50.     if humanoidRootPart and not humanoidRootPart:FindFirstChild("Highlight") then
  51.         local highlightClone = Instance.new("Highlight")
  52.         highlightClone.Name = "Highlight"
  53.         highlightClone.Adornee = character
  54.         highlightClone.Parent = humanoidRootPart
  55.         highlightClone.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
  56.         highlightClone.FillColor = colourChosen
  57.         highlightClone.OutlineColor = Color3.fromRGB(255, 255, 255)
  58.         highlightClone.FillTransparency = 0.5
  59.     end
  60. end
  61.  
  62. local function removeHighlightFromCharacter(character)
  63.     if not character then return end
  64.     local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  65.     if humanoidRootPart then
  66.         for _, obj in ipairs(humanoidRootPart:GetChildren()) do
  67.             if obj:IsA("Highlight") then
  68.                 obj:Destroy()
  69.             end
  70.         end
  71.     end
  72. end
  73.  
  74. local function updateHighlights()
  75.     for _, player in ipairs(Players:GetPlayers()) do
  76.         local character = getCharacter(player)
  77.         if character then
  78.             if _G.ESPToggle then
  79.                 addHighlightToCharacter(player, character)
  80.             else
  81.                 removeHighlightFromCharacter(character)
  82.             end
  83.         end
  84.     end
  85. end
  86.  
  87. RunService.RenderStepped:Connect(updateHighlights)
  88.  
  89. Players.PlayerAdded:Connect(function(player)
  90.     player.CharacterAdded:Connect(function(character)
  91.         if _G.ESPToggle then
  92.             addHighlightToCharacter(player, character)
  93.         end
  94.     end)
  95. end)
  96.  
  97. Players.PlayerRemoving:Connect(function(playerRemoved)
  98.     removeHighlightFromCharacter(playerRemoved.Character)
  99. end)
  100.  
  101. toggleButton.MouseButton1Click:Connect(function()
  102.     _G.ESPToggle = not _G.ESPToggle
  103.     toggleButton.Text = _G.ESPToggle and "ESP ON" or "ESP OFF"
  104. end)
  105.  
  106. UserInputService.InputBegan:Connect(function(input, gameProcessed)
  107.     if input.KeyCode == Enum.KeyCode.H and not gameProcessed then
  108.         mainFrame.Visible = not mainFrame.Visible
  109.     end
  110. end)
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement