task.defer(function()while true do task.wait(.25)for G,r in ActiveMobs do task.spawn(function()if not r.isDead and not r.Destroyed then local t,q=AI:GetClosestPlayer(r)local y=r.Enemy if r.Root.Anchored then r.Root.Anchored=false end if not r.Root:GetNetworkOwner()then r.Root:SetNetworkOwner(t)task.wait(.05)end if t and y then y:MoveTo((t.Character:GetPivot()).Position,t.Character.PrimaryPart)else ActiveMobs[G]=nil r.Root:SetNetworkOwner()y:MoveTo(r.Origin.Position)end AI:RequestJump(r)else ActiveMobs[G]=nil end end)end end end)return AI

task.defer(function()
	while true do
		task.wait(1/4)
		for MobInstance, Mob in ActiveMobs do
			task.spawn(function()
				if not Mob.isDead and not Mob.Destroyed then
					local Player, m = AI:GetClosestPlayer(Mob)
					local Enemy = Mob.Enemy
					
					-- Simulation
					if Mob.Root.Anchored then
						Mob.Root.Anchored = false
					end
					if not Mob.Root:GetNetworkOwner() then
						Mob.Root:SetNetworkOwner(Player)
						task.wait(0.05) -- Give physics more time so it doesn't appear as choppy
					end
					
					-- Tracking
					if Player and Enemy then
						Enemy:MoveTo(Player.Character:GetPivot().Position, Player.Character.PrimaryPart)
					else
						ActiveMobs[MobInstance] = nil
						Mob.Root:SetNetworkOwner()
						Enemy:MoveTo(Mob.Origin.Position)
					end
					
					-- Jumping
					AI:RequestJump(Mob)
				else
					ActiveMobs[MobInstance] = nil
				end
			end)
		end
	end
end)

return AI
