local RED = Color3.fromRGB(255, 0, 0) local BLUE = Color3.fromRGB(0, 0, 255) local PURPLE = Color3.fromRGB(170, 0, 255) local FillColor = Color3.fromRGB(0, 0, 0) local DepthMode = Enum.HighlightDepthMode.AlwaysOnTop local FillTransparency = 1 -- Set to 0.98 if they still flicker at distance local OutlineTransparency = 0 local Players = game:GetService("Players") local lp = Players.LocalPlayer -- Using PlayerGui as a safe container for the highlights local PlayerGui = lp:WaitForChild("PlayerGui") local Storage = Instance.new("Folder") Storage.Name = "ESP_Storage" Storage.Parent = PlayerGui local gunTypes = { ["PPK"] = "Purple", ["UMP45"] = "Purple", ["UMP45M"] = "Purple", ["Type79"] = "Red", ["SVT40"] = "Red", ["Luty"] = "Red", ["VintorezO"] = "Red", ["VintorezN"] = "Red", ["M16A4"] = "Red", ["AK74"] = "Red", ["AKS74U"] = "Red", ["R870"] = "Red", ["R870A"] = "Red", ["Saiga 12"] = "Red", ["KS23M"] = "Red", ["P320"] = "Red", ["Obrez Mosin"] = "Red", ["TEC9"] = "Red", ["G17S"] = "Red", ["G17SM"] = "Red", ["Deagle"] = "Red", ["Degle"] = "Red" } -- Scans both Backpack and Character for guns local function getInventoryHighlightColor(plr) local hasRed = false local hasPurple = false local function scan(container) if not container then return end for _, item in ipairs(container:GetChildren()) do local colorType = gunTypes[item.Name] if colorType == "Purple" then hasPurple = true elseif colorType == "Red" then hasRed = true end end end scan(plr:FindFirstChild("Backpack")) scan(plr.Character) if hasPurple then return PURPLE end if hasRed then return RED end return BLUE end local function CreateESP(plr) if plr == lp then return end -- We store connections in a table so we can disconnect old ones on respawn local playerConnections = {} local function cleanup() for _, conn in ipairs(playerConnections) do conn:Disconnect() end playerConnections = {} local oldHl = Storage:FindFirstChild(plr.Name) if oldHl then oldHl:Destroy() end end local function onCharacterAdded(char) cleanup() -- Clear any leftover highlights/connections from the previous life local hl = Instance.new("Highlight") hl.Name = plr.Name hl.Adornee = char hl.FillColor = FillColor hl.DepthMode = DepthMode hl.FillTransparency = FillTransparency hl.OutlineTransparency = OutlineTransparency hl.Parent = Storage local function update() hl.OutlineColor = getInventoryHighlightColor(plr) end -- Update when tools are added/removed from character (Equipping) table.insert(playerConnections, char.ChildAdded:Connect(update)) table.insert(playerConnections, char.ChildRemoved:Connect(update)) -- Update when tools move in/out of Backpack (Picking up/Dropping) local backpack = plr:WaitForChild("Backpack", 5) if backpack then table.insert(playerConnections, backpack.ChildAdded:Connect(update)) table.insert(playerConnections, backpack.ChildRemoved:Connect(update)) end update() -- Initial color check end -- Run whenever the character spawns or teleports table.insert(playerConnections, plr.CharacterAdded:Connect(onCharacterAdded)) -- If the character already exists when the script runs if plr.Character then onCharacterAdded(plr.Character) end end -- Setup for new players Players.PlayerAdded:Connect(CreateESP) -- Setup for players already in the server for _, v in ipairs(Players:GetPlayers()) do CreateESP(v) end -- Full cleanup when someone leaves Players.PlayerRemoving:Connect(function(plr) local oldHl = Storage:FindFirstChild(plr.Name) if oldHl then oldHl:Destroy() end end)