local ReplicatedStorage = game:GetService("ReplicatedStorage") local Events = ReplicatedStorage:FindFirstChild("Events") local RemoteEvents = Events:FindFirstChild("RemoteEvents") local AddHPBars = RemoteEvents:FindFirstChild("AddHPBars") local Workspace = game:GetService("Workspace") local CollectionService = game:GetService("CollectionService") local NPCFolders = Workspace:FindFirstChild("NPCFolders") local FriendlyFolder = NPCFolders:FindFirstChild("FriendlyFolder") local EnemyFolder = NPCFolders:FindFirstChild("EnemyFolder") local ProcessedNPCs = {} local function GetHealthbarType(npc, defaultBarType) if CollectionService:HasTag(npc, "Friendly") then return "Friendly" end if CollectionService:HasTag(npc, "Boss") then return "Boss" end return defaultBarType end local function ApplyHealthbarToNPC(npc, defaultBarType) if npc and not ProcessedNPCs[npc] then ProcessedNPCs[npc] = true task.spawn(function() local head = npc:WaitForChild("Head", 5) local humanoid = npc:WaitForChild("Humanoid", 5) if head and humanoid then local barType = GetHealthbarType(npc, defaultBarType) pcall(function() firesignal(AddHPBars.OnClientEvent, npc, barType, head) end) else ProcessedNPCs[npc] = nil end end) end end if FriendlyFolder then task.spawn(function() local children = FriendlyFolder:GetChildren() for _, npc in ipairs(children) do ApplyHealthbarToNPC(npc, "Friendly") task.wait(0.02) end end) FriendlyFolder.ChildAdded:Connect(function(npc) ApplyHealthbarToNPC(npc, "Friendly") end) end if EnemyFolder then task.spawn(function() local children = EnemyFolder:GetChildren() for _, npc in ipairs(children) do ApplyHealthbarToNPC(npc, "Enemy") task.wait(0.02) end end) EnemyFolder.ChildAdded:Connect(function(npc) ApplyHealthbarToNPC(npc, "Enemy") end) end