
Key Required
ESP Script (PC Only)
Lua Script•502 lines (15351 chars)
--[[
Advanced Team ESP Script for Roblox
Features:
- Press P to toggle ESP
- Green highlight for teammates
- Red highlight for enemies
- Health bars above characters
- Bulletproof cleanup system
- Game verification (Afghanistan only)
- PC/Laptop only restriction
- GUI notification with exit button
]]
-- Configuration
local ESP_ENABLED = false
local TEAM_COLOR = Color3.fromRGB(0, 255, 0) -- Green for team
local ENEMY_COLOR = Color3.fromRGB(255, 0, 0) -- Red for enemies
local FILL_TRANSPARENCY = 0.5
local OUTLINE_TRANSPARENCY = 1
-- Game Verification
local ALLOWED_PLACE_ID = 9679014784 -- Afghanistan game ID
-- Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local LocalPlayer = Players.LocalPlayer
-- Verify game and device
local function verifyAccess()
-- Check if it's the Afghanistan game
local placeId = game.PlaceId
if placeId ~= ALLOWED_PLACE_ID then
LocalPlayer:Kick("Wrong game, only for Afghanistan")
return false
end
-- Check if on PC/Laptop (not mobile/tablet)
local userInputService = game:GetService("UserInputService")
-- Check if touch is enabled (mobile/tablet)
if userInputService.TouchEnabled then
-- Additional check: if it's a touch device AND has small screen, it's mobile
local screenSize = workspace.CurrentCamera.ViewportSize
if screenSize.X <= 1200 then
LocalPlayer:Kick("Wrong game, only for Afghanistan")
return false
end
end
-- Check for mobile-specific features
local isMobile = false
-- Check platform type
local platform = userInputService:GetPlatform()
if platform == Enum.Platform.Android or platform == Enum.Platform.IOS then
isMobile = true
end
-- Check for mobile-only UI
if not isMobile and userInputService.GamepadEnabled then
-- Could be a console or mobile with gamepad
if userInputService.TouchEnabled then
isMobile = true
end
end
if isMobile then
LocalPlayer:Kick("Wrong game, only for Afghanistan")
return false
end
return true
end
-- Check if we have access
local hasAccess = verifyAccess()
if not hasAccess then
return
end
-- Create notification GUI
local function createNotification()
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "ESP_Notification"
screenGui.ResetOnSpawn = false
screenGui.IgnoreGuiInset = true
screenGui.Parent = LocalPlayer:WaitForChild("PlayerGui")
-- Main frame
local mainFrame = Instance.new("Frame")
mainFrame.Name = "MainFrame"
mainFrame.Size = UDim2.new(0, 300, 0, 50)
mainFrame.Position = UDim2.new(0.5, -150, 0, 20)
mainFrame.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
mainFrame.BackgroundTransparency = 0.3
mainFrame.BorderSizePixel = 2
mainFrame.BorderColor3 = Color3.fromRGB(255, 255, 255)
mainFrame.ZIndex = 1000
mainFrame.Parent = screenGui
-- Add rounded corners effect
local uiCorner = Instance.new("UICorner")
uiCorner.CornerRadius = UDim.new(0, 8)
uiCorner.Parent = mainFrame
-- Text label
local textLabel = Instance.new("TextLabel")
textLabel.Name = "NotificationText"
textLabel.Size = UDim2.new(1, -40, 1, 0)
textLabel.Position = UDim2.new(0, 10, 0, 0)
textLabel.BackgroundTransparency = 1
textLabel.Text = "Press (P) to enable ESP."
textLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
textLabel.TextScaled = true
textLabel.Font = Enum.Font.SourceSansBold
textLabel.ZIndex = 1001
textLabel.Parent = mainFrame
-- Exit button
local exitButton = Instance.new("TextButton")
exitButton.Name = "ExitButton"
exitButton.Size = UDim2.new(0, 25, 0, 25)
exitButton.Position = UDim2.new(1, -30, 0, 12)
exitButton.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
exitButton.BackgroundTransparency = 0.3
exitButton.Text = "X"
exitButton.TextColor3 = Color3.fromRGB(255, 255, 255)
exitButton.TextScaled = true
exitButton.Font = Enum.Font.SourceSansBold
exitButton.ZIndex = 1002
exitButton.Parent = mainFrame
-- Add rounded corners to exit button
local exitCorner = Instance.new("UICorner")
exitCorner.CornerRadius = UDim.new(0, 4)
exitCorner.Parent = exitButton
-- Hover effect for exit button
exitButton.MouseEnter:Connect(function()
exitButton.BackgroundTransparency = 0
end)
exitButton.MouseLeave:Connect(function()
exitButton.BackgroundTransparency = 0.3
end)
-- Exit button click function
exitButton.MouseButton1Click:Connect(function()
-- Animate and destroy
local tween = TweenService:Create(mainFrame, TweenInfo.new(0.3), {BackgroundTransparency = 1})
tween:Play()
task.wait(0.3)
screenGui:Destroy()
end)
-- Auto-hide after 10 seconds
task.wait(10)
if screenGui and screenGui.Parent then
local fadeTween = TweenService:Create(mainFrame, TweenInfo.new(0.5), {BackgroundTransparency = 0.7})
fadeTween:Play()
task.wait(0.5)
screenGui:Destroy()
end
return screenGui
end
-- Create the notification
createNotification()
-- Storage for ESP instances
local espInstances = {}
local allConnections = {}
-- Function to completely clean up a player's ESP
local function cleanupESP(player)
if not player then return end
local espData = espInstances[player]
if not espData then return end
-- Disconnect all connections for this player
if espData.connections then
for _, conn in ipairs(espData.connections) do
pcall(function()
conn:Disconnect()
end)
end
espData.connections = {}
end
-- Destroy highlight if it exists
if espData.highlight then
pcall(function()
espData.highlight:Destroy()
end)
espData.highlight = nil
end
-- Destroy all GUI elements
if espData.screenGui then
pcall(function()
espData.screenGui:Destroy()
end)
espData.screenGui = nil
end
-- Clear all other references
espData.healthBar = nil
espData.healthFill = nil
espData.nameLabel = nil
espData.character = nil
espData.humanoid = nil
-- Remove from table
espInstances[player] = nil
end
-- Create health bar GUI
local function createHealthBar(player)
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "ESP_HealthBar_" .. player.UserId
screenGui.ResetOnSpawn = false
screenGui.IgnoreGuiInset = true
screenGui.Parent = LocalPlayer:WaitForChild("PlayerGui")
local healthBar = Instance.new("Frame")
healthBar.Name = "HealthBar"
healthBar.Size = UDim2.new(0, 50, 0, 6)
healthBar.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
healthBar.BorderSizePixel = 1
healthBar.BorderColor3 = Color3.fromRGB(255, 255, 255)
healthBar.Visible = false
healthBar.ZIndex = 999
healthBar.Parent = screenGui
local healthFill = Instance.new("Frame")
healthFill.Name = "HealthFill"
healthFill.Size = UDim2.new(1, 0, 1, 0)
healthFill.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
healthFill.BorderSizePixel = 0
healthFill.ZIndex = 1000
healthFill.Parent = healthBar
local nameLabel = Instance.new("TextLabel")
nameLabel.Name = "NameLabel"
nameLabel.Size = UDim2.new(1, 0, 0, 20)
nameLabel.Position = UDim2.new(0, 0, 1, 2)
nameLabel.BackgroundTransparency = 1
nameLabel.TextScaled = true
nameLabel.Font = Enum.Font.SourceSansBold
nameLabel.TextColor3 = Color3.fromRGB(255, 255, 255)
nameLabel.TextStrokeTransparency = 0
nameLabel.TextStrokeColor3 = Color3.fromRGB(0, 0, 0)
nameLabel.Text = player.Name
nameLabel.ZIndex = 1001
nameLabel.Parent = healthBar
return screenGui, healthBar, healthFill, nameLabel
end
-- Get team color for a player
local function getPlayerTeamColor(player)
if player == LocalPlayer then
return TEAM_COLOR
end
-- Try to get team from various systems
local team = player.Team
if team then
if player.Neutral then
return Color3.fromRGB(255, 255, 0) -- Yellow for neutral
end
-- Compare team colors
local localTeam = LocalPlayer.Team
if localTeam and team == localTeam then
return TEAM_COLOR
else
return ENEMY_COLOR
end
end
-- Fallback: check for TeamService
local teamService = game:GetService("Teams")
local localTeam = LocalPlayer.Team
if localTeam then
for _, t in ipairs(teamService:GetTeams()) do
if t == team then
if t == localTeam then
return TEAM_COLOR
else
return ENEMY_COLOR
end
end
end
end
-- If no team system, use player color
return ENEMY_COLOR
end
-- Set up ESP for a player's character
local function setupCharacterESP(player, character)
if not player or not character or not ESP_ENABLED then return end
-- Clean up any existing ESP for this player first
cleanupESP(player)
-- Create Highlight
local highlight = Instance.new("Highlight")
highlight.Name = "ESP_Highlight"
highlight.FillTransparency = FILL_TRANSPARENCY
highlight.OutlineTransparency = OUTLINE_TRANSPARENCY
highlight.FillColor = getPlayerTeamColor(player)
highlight.OutlineColor = getPlayerTeamColor(player)
highlight.Parent = character
-- Create health bar
local screenGui, healthBar, healthFill, nameLabel = createHealthBar(player)
-- Store instances
local espData = {
highlight = highlight,
screenGui = screenGui,
healthBar = healthBar,
healthFill = healthFill,
nameLabel = nameLabel,
character = character,
humanoid = character:FindFirstChildOfClass("Humanoid"),
connections = {}
}
espInstances[player] = espData
-- Create update connection
local updateConn
updateConn = RunService.RenderStepped:Connect(function()
if not ESP_ENABLED then return end
if not espInstances[player] then return end
if not espData.character then return end
if not espData.character.Parent then
cleanupESP(player)
return
end
local rootPart = espData.character:FindFirstChild("HumanoidRootPart")
local humanoid = espData.character:FindFirstChildOfClass("Humanoid")
if rootPart and humanoid then
local head = espData.character:FindFirstChild("Head")
if head then
local screenPos, onScreen = workspace.CurrentCamera:WorldToScreenPoint(head.Position + Vector3.new(0, 3, 0))
if onScreen then
espData.healthBar.Visible = true
espData.healthBar.Position = UDim2.new(0, screenPos.X - 25, 0, screenPos.Y)
local healthPercent = humanoid.Health / humanoid.MaxHealth
espData.healthFill.Size = UDim2.new(healthPercent, 0, 1, 0)
if healthPercent > 0.5 then
espData.healthFill.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
elseif healthPercent > 0.25 then
espData.healthFill.BackgroundColor3 = Color3.fromRGB(255, 255, 0)
else
espData.healthFill.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
end
espData.nameLabel.Text = player.Name
else
espData.healthBar.Visible = false
end
else
espData.healthBar.Visible = false
end
else
espData.healthBar.Visible = false
end
end)
table.insert(espData.connections, updateConn)
-- Clean up when character dies
if espData.humanoid then
local diedConn = espData.humanoid.Died:Connect(function()
task.wait(0.1)
cleanupESP(player)
end)
table.insert(espData.connections, diedConn)
end
-- Clean up when character is removed
local removedConn = character.AncestryChanged:Connect(function()
if not character.Parent then
task.wait(0.1)
cleanupESP(player)
end
end)
table.insert(espData.connections, removedConn)
end
-- Create ESP for a player
local function createESP(player)
if player == LocalPlayer then return end
-- Handle character added
local charAddedConn
charAddedConn = player.CharacterAdded:Connect(function(character)
task.wait(0.5) -- Wait for character to load
if ESP_ENABLED then
setupCharacterESP(player, character)
end
end)
-- Store the character added connection
if not allConnections[player] then
allConnections[player] = {}
end
table.insert(allConnections[player], charAddedConn)
-- Check if character already exists
if player.Character then
task.wait(0.1)
if ESP_ENABLED then
setupCharacterESP(player, player.Character)
end
end
end
-- Toggle ESP
local function toggleESP()
ESP_ENABLED = not ESP_ENABLED
if ESP_ENABLED then
-- Enable ESP for all players
for _, player in ipairs(Players:GetPlayers()) do
if player ~= LocalPlayer then
createESP(player)
end
end
else
-- Disable ESP for all players
for _, player in ipairs(Players:GetPlayers()) do
cleanupESP(player)
end
-- Clear all stored connections
for _, connections in pairs(allConnections) do
for _, conn in ipairs(connections) do
pcall(function()
conn:Disconnect()
end)
end
end
allConnections = {}
end
-- Print status
print("ESP " .. (ESP_ENABLED and "ENABLED" or "DISABLED"))
end
-- Key bind
LocalPlayer:GetMouse().KeyDown:Connect(function(key)
if key:lower() == "p" then
toggleESP()
end
end)
-- Connect player events
Players.PlayerAdded:Connect(function(player)
createESP(player)
end)
Players.PlayerRemoving:Connect(function(player)
cleanupESP(player)
-- Clean up all connections for this player
if allConnections[player] then
for _, conn in ipairs(allConnections[player]) do
pcall(function()
conn:Disconnect()
end)
end
allConnections[player] = nil
end
end)
-- Initial setup
for _, player in ipairs(Players:GetPlayers()) do
if player ~= LocalPlayer then
createESP(player)
end
end
-- Status message
print("ESP Script loaded - Press P to toggle")
print("Game verified: Afghanistan")Features & Information
Simple ESP Feature for the game: Afghanistan
(PC Only)
Community Comments (0)
No comments yet for this script.
