Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local colourTable = {
- Green = Color3.fromRGB(0, 255, 0),
- Blue = Color3.fromRGB(0, 0, 255),
- Red = Color3.fromRGB(255, 0, 0),
- Yellow = Color3.fromRGB(255, 255, 0),
- Orange = Color3.fromRGB(255, 165, 0),
- Purple = Color3.fromRGB(128, 0, 128)
- }
- local colourChosen = colourTable["Red"] -- Set your preferred colour here
- _G.ESPToggle = false -- Variable to toggle ESP
- -- Services and player references
- local Players = game:GetService("Players")
- local LocalPlayer = Players.LocalPlayer
- local RunService = game:GetService("RunService")
- local UserInputService = game:GetService("UserInputService")
- local Workspace = game:GetService("Workspace")
- -- Screen GUI setup
- local screenGui = Instance.new("ScreenGui")
- screenGui.Name = "ESPToggleGui"
- screenGui.Parent = game.CoreGui
- local mainFrame = Instance.new("Frame")
- mainFrame.Name = "MainFrame"
- mainFrame.Size = UDim2.new(1, 0, 1, 0)
- mainFrame.BackgroundTransparency = 1
- mainFrame.Parent = screenGui
- local toggleButton = Instance.new("TextButton")
- toggleButton.Name = "ToggleButton"
- toggleButton.Size = UDim2.new(0, 200, 0, 50)
- toggleButton.Position = UDim2.new(0.5, -100, 0.5, -25)
- toggleButton.Text = "Toggle ESP"
- toggleButton.Parent = mainFrame
- local function getCharacter(player)
- return player.Character or Workspace:FindFirstChild(player.Name)
- end
- -- Checks if a player is on the same team as the local player
- local function isEnemy(player)
- if not player.Team or not LocalPlayer.Team then return true end
- return player.Team ~= LocalPlayer.Team
- end
- local function addHighlightToCharacter(player, character)
- if player == LocalPlayer or not isEnemy(player) then return end
- local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
- if humanoidRootPart and not humanoidRootPart:FindFirstChild("Highlight") then
- local highlightClone = Instance.new("Highlight")
- highlightClone.Name = "Highlight"
- highlightClone.Adornee = character
- highlightClone.Parent = humanoidRootPart
- highlightClone.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
- highlightClone.FillColor = colourChosen
- highlightClone.OutlineColor = Color3.fromRGB(255, 255, 255)
- highlightClone.FillTransparency = 0.5
- end
- end
- local function removeHighlightFromCharacter(character)
- if not character then return end
- local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
- if humanoidRootPart then
- for _, obj in ipairs(humanoidRootPart:GetChildren()) do
- if obj:IsA("Highlight") then
- obj:Destroy()
- end
- end
- end
- end
- local function updateHighlights()
- for _, player in ipairs(Players:GetPlayers()) do
- local character = getCharacter(player)
- if character then
- if _G.ESPToggle then
- addHighlightToCharacter(player, character)
- else
- removeHighlightFromCharacter(character)
- end
- end
- end
- end
- RunService.RenderStepped:Connect(updateHighlights)
- Players.PlayerAdded:Connect(function(player)
- player.CharacterAdded:Connect(function(character)
- if _G.ESPToggle then
- addHighlightToCharacter(player, character)
- end
- end)
- end)
- Players.PlayerRemoving:Connect(function(playerRemoved)
- removeHighlightFromCharacter(playerRemoved.Character)
- end)
- toggleButton.MouseButton1Click:Connect(function()
- _G.ESPToggle = not _G.ESPToggle
- toggleButton.Text = _G.ESPToggle and "ESP ON" or "ESP OFF"
- end)
- UserInputService.InputBegan:Connect(function(input, gameProcessed)
- if input.KeyCode == Enum.KeyCode.H and not gameProcessed then
- mainFrame.Visible = not mainFrame.Visible
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement