Pre-existing enemies glitch out when an enemy dies with the bomb as well of the enemy itself glitching out

Hello There!

I am having an issue with my Mann vs Machine-like game, it’s the AI of the enemies, if the title confused you, the issue is that when multiple of the same AI (Such as three) and 1/3rd off them got the bomb, they suddenly won’t move towards the hatchet/statue. And even worse is that when the enemy with the bomb dies, the other enemies won’t try to get the bomb.

This is the script of the enemy; (Sorry if it’s sloppy, it’s my first time doing such things)

local NPC = script.Parent
local Humanoid = NPC:WaitForChild("Humanoid")
local RootPart = NPC:WaitForChild("HumanoidRootPart")

local PathFindingService = game:GetService("PathfindingService")

local Bomb = workspace:WaitForChild("Bomb")
local Hatchet = workspace:WaitForChild("BOMBDROP")

local HasBomb = NPC:GetAttribute("HasBomb")
local ListofStatus = {
	"GetBomb",
	"MoveToStatue",
	"Fight"
}
local Status = "MoveToStatue" ---If a NPC spawns, unless if the bomb is available, or it's a boss, it will move towards the statue.
--[[
What the statuses do:
1. GetBomb - This will cause the NPC to get the bomb to carry it, if possible.
2. MoveToStatue - Cause the NPC to move to the statue or end point to drop the bomb.
3. Fight - The NPC will simply pathfind the nearest player to fight.
]]
local AggroRange = 5 -- This basically just tells how far the NPC can pick up bomb if available.

task.wait(5.8)
game:GetService("RunService").Stepped:Connect(function()
	if HasBomb == false then
		task.spawn(function()
			local Path = PathFindingService:CreatePath()
			Path:ComputeAsync(NPC.HumanoidRootPart.Position,Bomb.Position)
			if Path.Status == Enum.PathStatus.Success then
				local Waypoints = Path:GetWaypoints()
				
				if Waypoints and Waypoints[2] then
					local Data = Waypoints[2]
					
					Humanoid:MoveTo(Data.Position)
				end
			end
		end)
		if NPC:GetAttribute("HasBomb") == true then
			HasBomb = true
		end
	elseif HasBomb then
		local Path = PathFindingService:CreatePath()
		Path:ComputeAsync(NPC.HumanoidRootPart.Position,Hatchet.Position)
		if Path.Status == Enum.PathStatus.Success then
			local Waypoints = Path:GetWaypoints()

			if Waypoints and Waypoints[2] then
				local Data = Waypoints[2]

				Humanoid:MoveTo(Data.Position)
			end
		end
	end
end)
1 Like